***************************************************************/
/**
- * A generic Domain Object
+ * A generic Domain Object.
*
- * @package TYPO3
- * @subpackage extbase
+ * All Model domain objects need to inherit from either AbstractEntity or AbstractValueObject, as this provides important framework information.
+ *
+ * @package Extbase
+ * @subpackage DomainObject
* @version $ID:$
*/
-abstract class Tx_ExtBase_DomainObject_AbstractDomainObject implements Tx_ExtBase_DomainObject_DomainObjectInterface {
+abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbase_DomainObject_DomainObjectInterface {
/**
- * @var string The uid
+ * @var int The uid
*/
protected $uid;
/**
- * @var An array holding the clean property values. Set right after reconstitution of the object
+ * TRUE if the object is a clone
+ * @var boolean
*/
- private $_cleanProperties = NULL;
+ private $isClone = FALSE;
/**
* The generic constructor. If you want to implement your own __constructor() method in your Domain Object you have to call
* @return void
*/
public function __wakeup() {
- foreach ($GLOBALS['ExtBase']['reconstituteObject']['properties'] as $propertyName => $value) {
- $this->_reconstituteProperty($propertyName, $value);
- }
$this->initializeObject();
}
}
/**
- * Getter for uid
+ * Getter for uid.
*
- * @return string
+ * @return int the uid or NULL if none set yet.
*/
- public function getUid() {
- return $this->uid;
+ final public function getUid() {
+ return ($this->uid === NULL ? NULL : (int)$this->uid);
}
/**
- * Reconstitutes a property. This method should only be called at reconstitution time!
+ * Reconstitutes a property. Only for internal use.
*
* @param string $propertyName
* @param string $value
* @return void
- * @internal
*/
- public function _reconstituteProperty($propertyName, $value) {
- if (property_exists($this, $propertyName)) {
- $this->$propertyName = $value;
+ public function _setProperty($propertyName, $propertyValue) {
+ if ($this->_hasProperty($propertyName)) {
+ $this->$propertyName = $propertyValue;
+ return TRUE;
}
+ return FALSE;
+ }
+
+ /**
+ * Returns the property value of the given property name. Only for internal use.
+ *
+ * @return mixed The propertyValue
+ */
+ public function _getProperty($propertyName) {
+ return $this->$propertyName;
+ }
+
+ /**
+ * Returns a hash map of property names and property values. Only for internal use.
+ *
+ * @return array The properties
+ */
+ public function _getProperties() {
+ $properties = get_object_vars($this);
+ unset($properties['_cleanProperties']);
+ return $properties;
+ }
+
+ /**
+ * Returns the property value of the given property name. Only for internal use.
+ *
+ * @return boolean TRUE bool true if the property exists, FALSE if it doesn't exist or
+ * NULL in case of an error.
+ */
+ public function _hasProperty($propertyName) {
+ return property_exists($this, $propertyName);
+ }
+
+ /**
+ * Returns TRUE if the object is new (the uid was not set, yet). Only for internal use
+ *
+ * @return boolean
+ */
+ public function _isNew() {
+ return $this->uid === NULL;
}
/**
* from the database
*
* @return void
- * @internal
*/
public function _memorizeCleanState() {
- $this->initializeCleanProperties();
- $cleanProperties = array();
- foreach ($this->_cleanProperties as $propertyName => $propertyValue) {
- $cleanProperties[$propertyName] = $this->$propertyName;
- }
- $this->_cleanProperties = $cleanProperties;
}
-
+
/**
- * Returns TRUE if the properties were modified after reconstitution
+ * Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
*
* @return boolean
- * @internal
*/
- public function _isDirty() {
- if (!is_array($this->_cleanProperties)) throw new Tx_ExtBase_Persistence_Exception_CleanStateNotMemorized('The clean state of the object "' . get_class($this) . '" has not been memorized before asking _isDirty().', 1233309106);
- if ($this->uid !== NULL && $this->uid != $this->_cleanProperties['uid']) throw new Tx_ExtBase_Persistence_Exception_TooDirty('The uid "' . $this->uid . '" has been modified, that is simply too much.', 1222871239);
- foreach ($this->_cleanProperties as $propertyName => $propertyValue) {
- if ($this->$propertyName !== $propertyValue) return TRUE;
- }
+ public function _isDirty($propertyName = NULL) {
return FALSE;
}
/**
- * Returns a hash map of property names and property values
+ * Returns TRUE if the object has been clonesd, cloned, FALSE otherwise.
*
- * @return array The properties
- * @internal
+ * @return boolean TRUE if the object has been cloned
*/
- public function _getProperties() {
- $properties = get_object_vars($this);
- unset($properties['_cleanProperties']);
- return $properties;
+ public function _isClone() {
+ return $this->isClone;
}
/**
- * Returns a hash map of dirty properties and $values
+ * Setter whether this Domain Object is a clone of another one.
+ * NEVER SET THIS PROPERTY DIRECTLY. We currently need it to make the
+ * _isDirty check inside AbstractEntity work, but it is just a work-
+ * around right now.
*
- * @return boolean
- * @internal
- */
- public function _getDirtyProperties() {
- if (!is_array($this->_cleanProperties)) throw new Tx_ExtBase_Persistence_Exception_CleanStateNotMemorized('The clean state of the object "' . get_class($this) . '" has not been memorized before asking _isDirty().', 1233309106);
- if ($this->uid !== NULL && $this->uid != $this->_cleanProperties['uid']) throw new Tx_ExtBase_Persistence_Exception_TooDirty('The uid "' . $this->uid . '" has been modified, that is simply too much.', 1222871239);
- $dirtyProperties = array();
- foreach ($this->_cleanProperties as $propertyName => $propertyValue) {
- if ($this->$propertyName !== $propertyValue) {
- $dirtyProperties[$propertyName] = $this->$propertyName;
- }
- }
- return $dirtyProperties;
+ * @param boolean $clone
+ */
+ public function _setClone($clone) {
+ $this->isClone = (boolean)$clone;
}
/**
- * Saves a copy of values of the persitable properties inside the object itself. This method is normally
- * called right after it's reconstitution from a storage.
+ * Clone method. Sets the _isClone property.
*
* @return void
- * @author Jochen Rau <jochen.rau@typoplanet.de>
*/
- private function initializeCleanProperties() {
- $properties = get_object_vars($this);
- $dataMapper = t3lib_div::makeInstance('Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper'); // singleton
- foreach ($properties as $propertyName => $propertyValue) {
- if ($dataMapper->isPersistableProperty(get_class($this), $propertyName)) {
- $this->_cleanProperties[$propertyName] = NULL;
- }
- }
- $this->_cleanProperties['uid'] = NULL;
+ public function __clone() {
+ $this->isClone = TRUE;
}
-
}
?>
\ No newline at end of file