From 0c0e6fd6377c4c99d56505e1be45dbfb457fd90e Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 23 Oct 2006 17:34:36 +0000 Subject: [PATCH] added Doctrine_Record::state() --- lib/Doctrine/Record.php | 32 +++++++++++++++++++++++++ lib/Doctrine/Record/Exception.php | 30 ++++++++++++++++++++--- lib/Doctrine/Record/State/Exception.php | 29 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 lib/Doctrine/Record/State/Exception.php diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index b9179c005..d452c507d 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -499,6 +499,38 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite final public function getState() { return $this->_state; } + /** + * state + * returns / assigns the state of this record + * + * @param integer|string $state if set, this method tries to set the record state to $state + * + * @throws Doctrine_Record_State_Exception if trying to set an unknown state + * @return null|integer + */ + public function state($state = null) { + if($state == null) { + return $this->_state; + } + if(is_integer($state)) { + if($state >= 1 && $state <= 6) + $this->_state = $state; + } elseif(is_string($state)) { + $upper = strtoupper($state); + switch($upper) { + case 'DIRTY': + case 'CLEAN': + case 'TDIRTY': + case 'TCLEAN': + case 'PROXY': + case 'DELETED': + $this->_state = constant('Doctrine_Record::STATE_' . $upper); + break; + } + } + + throw new Doctrine_Record_State_Exception('Unknown record state ' . $state); + } /** * refresh * refresh internal data from the database diff --git a/lib/Doctrine/Record/Exception.php b/lib/Doctrine/Record/Exception.php index f1447fd77..19ce8a416 100644 --- a/lib/Doctrine/Record/Exception.php +++ b/lib/Doctrine/Record/Exception.php @@ -1,5 +1,29 @@ . + */ Doctrine::autoload('Doctrine_Exception'); - -class Doctrine_Record_Exception extends Doctrine_Exception { } - +/** + * Doctrine_Exception + * + * @package Doctrine ORM + * @url www.phpdoctrine.com + * @license LGPL + */ +class Doctrine_Record_Exception extends Doctrine_Exception { } diff --git a/lib/Doctrine/Record/State/Exception.php b/lib/Doctrine/Record/State/Exception.php new file mode 100644 index 000000000..4f06ee775 --- /dev/null +++ b/lib/Doctrine/Record/State/Exception.php @@ -0,0 +1,29 @@ +. + */ +Doctrine::autoload('Doctrine_Record_Exception'); +/** + * Doctrine_Exception + * + * @package Doctrine ORM + * @url www.phpdoctrine.com + * @license LGPL + */ +class Doctrine_Record_State_Exception extends Doctrine_Record_Exception { }