From 628aac0ef41eea6793c2cdebcd3fdb724560f133 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 25 Jun 2007 09:12:09 +0000 Subject: [PATCH] --- lib/Doctrine/Connection/UnitOfWork.php | 8 ++--- lib/Doctrine/Event.php | 48 +++++++++++++++++++------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index d08ecf9da..a95680800 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -145,7 +145,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->preSave($event); - if ( ! $event->getSkipOperation()) { + if ( ! $event->getOption('skipOperation')) { switch ($record->state()) { case Doctrine_Record::STATE_TDIRTY: $this->insert($record); @@ -188,7 +188,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $this->deleteComposites($record); - if ( ! $event->getSkipOperation()) { + if ( ! $event->getOption('skipOperation')) { $this->conn->transaction->addDelete($record); $record->state(Doctrine_Record::STATE_TCLEAN); @@ -340,7 +340,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->preUpdate($event); - if ( ! $event->getSkipOperation()) { + if ( ! $event->getOption('skipOperation')) { $array = $record->getPrepared(); if (empty($array)) { @@ -399,7 +399,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->preInsert($event); - if ( ! $event->getSkipOperation()) { + if ( ! $event->getOption('skipOperation')) { $array = $record->getPrepared(); if (empty($array)) { diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Event.php index 9a17378ca..d0f8529b4 100644 --- a/lib/Doctrine/Event.php +++ b/lib/Doctrine/Event.php @@ -75,9 +75,9 @@ class Doctrine_Event */ protected $_endedMicrotime; /** - * @var boolean $skipOperation + * @var array $_options an array of options */ - protected $_skipOperation = false; + protected $_options = array(); /** * constructor * @@ -138,28 +138,50 @@ class Doctrine_Event return $this->_code; } /** - * setSkipOperation + * getOption + * returns the value of an option * - * @return void + * @param string $option the name of the option + * @return mixed */ - public function setSkipOperation($bool) + public function getOption($option) { - $this->_skipOperation = (bool) $bool; + if ( ! isset($this->_options[$option])) { + return null; + } + + return $this->_options[$option]; } /** - * getSkipOperation + * skipOperation + * skips the next operation + * an alias for setOption('skipOperation', true) * - * @return void + * @return Doctrine_Event this object */ - public function getSkipOperation() + public function skipOperation() { - return $this->_skipOperation; + return $this->setOption('skipOperation', true); + } + /** + * setOption + * sets the value of an option + * + * @param string $option the name of the option + * @param mixed $value the value of the given option + * @return Doctrine_Event this object + */ + public function setOption($option, $value) + { + $this->_options[$option] = $value; + + return $this; } /** * start * starts the internal timer of this event * - * @return void + * @return Doctrine_Event this object */ public function start() { @@ -179,11 +201,13 @@ class Doctrine_Event * end * ends the internal timer of this event * - * @return void + * @return Doctrine_Event this object */ public function end() { $this->_endedMicrotime = microtime(true); + + return $this; } /** * getInvoker