Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Doctrine_Query_Listener {
- preDqlDelete(..)
- preDqlUpdate(..)
- }
- class MyUserSoftDeleteQueryListener implements Doctrine_Query_Listener {
- public function preDqlDelete($query) {
- // put the code here that parses the from dql parts to see if the "User" class is involved
- // this code can be considered for addition in Doctrine_Query if implemented properly (($query->containsClass('User') ?)
- // then modify the query here as needed
- }
- }
- Doctrine_Connection {
- ...
- protected $_queryListeners;
- public function addQueryListener(Doctrine_Query_Listener $listener) {
- ...
- }
- public function removeQueryListener(Doctrine_Query_Listener $listener) {
- ...
- }
- }
- Doctrine_Query {
- ...
- protected function _preQuery() {
- foreach ($this->_conn->getQueryListeners() as $listener) {
- when dql delete:
- $listener->preDqlDelete()
- when update
- $listener->preDqlUpdate()
- ...
- }
- }
- }
- // in bootstrap code
- $conn->addQueryListener(new MyUserSoftDeleteQueryListener());
- 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.
- class MyUser extends Doctrine_Record implements Doctrine_Query_Listener {
- // ... model stuff
- public function preDqlDelete($query..) {
- ....
- }
- public function preDqlDelete($query..) {
- ....
- }
- }
- // bootstrap
- $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