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 { }