2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * A generic Domain Object.
28 * All Model domain objects need to inherit from either AbstractEntity or AbstractValueObject, as this provides important framework information.
31 * @subpackage DomainObject
34 abstract class Tx_Extbase_DomainObject_AbstractDomainObject
implements Tx_Extbase_DomainObject_DomainObjectInterface
{
42 * TRUE if the object is a clone
45 private $isClone = FALSE;
48 * The generic constructor. If you want to implement your own __constructor() method in your Domain Object you have to call
49 * $this->initializeObject() in the first line of your constructor.
53 public function __construct() {
54 $this->initializeObject();
58 * This is the magic __wakeup() method. It's invoked by the unserialize statement in the reconstitution process
59 * of the object. If you want to implement your own __wakeup() method in your Domain Object you have to call
60 * parent::__wakeup() first!
64 public function __wakeup() {
65 $this->initializeObject();
69 * A template method to initialize an object. This can be used to manipulate the object after
70 * reconstitution and before the clean state of it's properties is stored.
74 protected function initializeObject() {
80 * @return int the uid or NULL if none set yet.
82 final public function getUid() {
83 return ($this->uid
=== NULL ?
NULL : (int)$this->uid
);
87 * Reconstitutes a property. Only for internal use.
89 * @param string $propertyName
90 * @param string $value
93 public function _setProperty($propertyName, $propertyValue) {
94 if ($this->_hasProperty($propertyName)) {
95 $this->$propertyName = $propertyValue;
102 * Returns the property value of the given property name. Only for internal use.
104 * @return mixed The propertyValue
106 public function _getProperty($propertyName) {
107 return $this->$propertyName;
111 * Returns a hash map of property names and property values. Only for internal use.
113 * @return array The properties
115 public function _getProperties() {
116 $properties = get_object_vars($this);
117 unset($properties['_cleanProperties']);
122 * Returns the property value of the given property name. Only for internal use.
124 * @return boolean TRUE bool true if the property exists, FALSE if it doesn't exist or
125 * NULL in case of an error.
127 public function _hasProperty($propertyName) {
128 return property_exists($this, $propertyName);
132 * Returns TRUE if the object is new (the uid was not set, yet). Only for internal use
136 public function _isNew() {
137 return $this->uid
=== NULL;
141 * Register an object's clean state, e.g. after it has been reconstituted
146 public function _memorizeCleanState() {
150 * Returns a hash map of dirty properties and $values. This is always the empty array for ValueObjects, because ValueObjects never change.
154 public function _getDirtyProperties() {
159 * Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
163 public function _isDirty() {
168 * Returns TRUE if the object has been clonesd, cloned, FALSE otherwise.
170 * @return boolean TRUE if the object has been cloned
172 public function _isClone() {
173 return $this->isClone
;
177 * Clone method. Sets the _isClone property.
181 public function __clone() {
182 $this->isClone
= TRUE;