From 6402b73b0893617b65e3334516c74e254f7fc96d Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 21 Sep 2006 12:15:48 +0000 Subject: [PATCH] Fixed Doctrine_EventListener_Chain, renamed onPreSetProperty to onSetProperty --- Doctrine/EventListener.php | 2 +- Doctrine/EventListener/AccessorInvoker.php | 2 +- Doctrine/EventListener/Chain.php | 191 ++++++++++++++++++++- Doctrine/Record.php | 2 +- 4 files changed, 185 insertions(+), 12 deletions(-) diff --git a/Doctrine/EventListener.php b/Doctrine/EventListener.php index 97bd6dd68..f9e23dce1 100644 --- a/Doctrine/EventListener.php +++ b/Doctrine/EventListener.php @@ -52,7 +52,7 @@ abstract class Doctrine_EventListener implements Doctrine_EventListener_Interfac public function onGetProperty(Doctrine_Record $record, $property, $value) { return $value; } - public function onPreSetProperty(Doctrine_Record $record, $property, $value) { + public function onSetProperty(Doctrine_Record $record, $property, $value) { return $value; } diff --git a/Doctrine/EventListener/AccessorInvoker.php b/Doctrine/EventListener/AccessorInvoker.php index 6d11be4d5..34c7a712c 100644 --- a/Doctrine/EventListener/AccessorInvoker.php +++ b/Doctrine/EventListener/AccessorInvoker.php @@ -64,7 +64,7 @@ class Doctrine_EventListener_AccessorInvoker extends Doctrine_EventListener { * @param mixed $value * @return mixed */ - public function onPreSetProperty(Doctrine_Record $record, $property, $value) { + public function onSetProperty(Doctrine_Record $record, $property, $value) { $method = 'set' . ucwords($property); if (method_exists($record, $method) && ! $this->lockSetCall) { diff --git a/Doctrine/EventListener/Chain.php b/Doctrine/EventListener/Chain.php index 2de3ad740..38d815454 100644 --- a/Doctrine/EventListener/Chain.php +++ b/Doctrine/EventListener/Chain.php @@ -38,16 +38,189 @@ class Doctrine_EventListener_Chain extends Doctrine_Access { public function set($key, Doctrine_EventListener $listener) { $this->listeners[$key] = $listener; } - /** - * this method should only be called internally by - * doctrine, since it doesn't do any method existence checking - * - * @param method $method - * @param array $args - */ - public function __call($method, $args) { + + + + public function onLoad(Doctrine_Record $record) { foreach($this->listeners as $listener) { - $listener->$method($args[0]); + $listener->onLoad($record); + } + } + public function onPreLoad(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreLoad($record); + } + } + + public function onSleep(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onSleep($record); + } + } + + public function onWakeUp(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onWakeUp($record); + } + } + + public function onUpdate(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onUpdate($record); + } + } + public function onPreUpdate(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreUpdate($record); + } + } + + public function onCreate(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onCreate($record); + } + } + public function onPreCreate(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreCreate($record); + } + } + + public function onSave(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onSave($record); + } + } + public function onPreSave(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreSave($record); + } + } + + public function onGetProperty(Doctrine_Record $record, $property, $value) { + foreach($this->listeners as $listener) { + $listener->onGetProperty($record); + } + } + public function onSetProperty(Doctrine_Record $record, $property, $value) { + foreach($this->listeners as $listener) { + $listener->onSetProperty($record); + } + } + + public function onInsert(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onInsert($record); + } + } + public function onPreInsert(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreInsert($record); + } + } + + public function onDelete(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onDelete($record); + } + } + public function onPreDelete(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreDelete($record); + } + } + + public function onEvict(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onEvict($record); + } + } + public function onPreEvict(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreEvict($record); + } + } + + public function onSaveCascade(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onSaveCascade($record); + } + } + public function onPreSaveCascade(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreSaveCascade($record); + } + } + + public function onDeleteCascade(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onDeleteCascade($record); + } + } + public function onPreDeleteCascade(Doctrine_Record $record) { + foreach($this->listeners as $listener) { + $listener->onPreDeleteCascade($record); + } + } + + public function onClose(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onClose($record); + } + } + public function onPreClose(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onPreClose($record); + } + } + + public function onOpen(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onOpen($record); + } + } + + public function onTransactionCommit(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onTransactionCommit($record); + } + } + public function onPreTransactionCommit(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onPreTransactionCommit($record); + } + } + + public function onTransactionRollback(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onTransactionRollback($record); + } + } + public function onPreTransactionRollback(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onPreTransactionRollback($record); + } + } + + public function onTransactionBegin(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onTransactionBegin($record); + } + } + public function onPreTransactionBegin(Doctrine_Connection $connection) { + foreach($this->listeners as $listener) { + $listener->onPreTransactionBegin($record); + } + } + + public function onCollectionDelete(Doctrine_Collection $collection) { + foreach($this->listeners as $listener) { + $listener->onCollectionDelete($record); + } + } + public function onPreCollectionDelete(Doctrine_Collection $collection) { + foreach($this->listeners as $listener) { + $listener->onPreCollectionDelete($record); } } } diff --git a/Doctrine/Record.php b/Doctrine/Record.php index 191d748f0..2b5c46428 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -731,7 +731,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite if($old !== $value) { // invoke the onPreSetProperty listener - $value = $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onPreSetProperty($this, $name, $value); + $value = $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value); if($value === null) $value = self::$null;