Guest User

Untitled

a guest
Apr 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. interface Doctrine_Query_Listener {
  2. preDqlDelete(..)
  3. preDqlUpdate(..)
  4. }
  5.  
  6. class MyUserSoftDeleteQueryListener implements Doctrine_Query_Listener {
  7. public function preDqlDelete($query) {
  8. // put the code here that parses the from dql parts to see if the "User" class is involved
  9. // this code can be considered for addition in Doctrine_Query if implemented properly (($query->containsClass('User') ?)
  10. // then modify the query here as needed
  11. }
  12. }
  13.  
  14. Doctrine_Connection {
  15. ...
  16. protected $_queryListeners;
  17.  
  18. public function addQueryListener(Doctrine_Query_Listener $listener) {
  19. ...
  20. }
  21.  
  22. public function removeQueryListener(Doctrine_Query_Listener $listener) {
  23. ...
  24. }
  25. }
  26.  
  27. Doctrine_Query {
  28. ...
  29. protected function _preQuery() {
  30. foreach ($this->_conn->getQueryListeners() as $listener) {
  31. when dql delete:
  32. $listener->preDqlDelete()
  33. when update
  34. $listener->preDqlUpdate()
  35. ...
  36. }
  37. }
  38. }
  39.  
  40.  
  41. // in bootstrap code
  42. $conn->addQueryListener(new MyUserSoftDeleteQueryListener());
  43.  
  44.  
  45. if you want to have the query modifications in your model, make the model the query listener, although i would consider that not as pretty since it puts 2 separate responsibilites into one class.
  46.  
  47. class MyUser extends Doctrine_Record implements Doctrine_Query_Listener {
  48. // ... model stuff
  49.  
  50. public function preDqlDelete($query..) {
  51. ....
  52. }
  53.  
  54. public function preDqlDelete($query..) {
  55. ....
  56. }
  57.  
  58. }
  59.  
  60. // bootstrap
  61. $conn->addQueryListener(new MyUser()); // MyUser is a Query listener after all, even if this may look strange to you
Add Comment
Please, Sign In to add comment