Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / DomainObject / AbstractDomainObject.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A generic Domain Object
27 *
28 * @package TYPO3
29 * @subpackage extbase
30 * @version $ID:$
31 */
32 abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbase_DomainObject_DomainObjectInterface {
33
34 /**
35 * @var string The uid
36 */
37 protected $uid;
38
39 /**
40 * The generic constructor. If you want to implement your own __constructor() method in your Domain Object you have to call
41 * $this->initializeObject() in the first line of your constructor.
42 *
43 * @var array
44 */
45 public function __construct() {
46 $this->initializeObject();
47 }
48
49 /**
50 * This is the magic __wakeup() method. It's invoked by the unserialize statement in the reconstitution process
51 * of the object. If you want to implement your own __wakeup() method in your Domain Object you have to call
52 * parent::__wakeup() first!
53 *
54 * @return void
55 */
56 public function __wakeup() {
57 foreach ($GLOBALS['Extbase']['reconstituteObject']['properties'] as $propertyName => $propertyValue) {
58 $this->_reconstituteProperty($propertyName, $propertyValue);
59 }
60 $this->initializeObject();
61 }
62
63 /**
64 * A template method to initialize an object. This can be used to manipulate the object after
65 * reconstitution and before the clean state of it's properties is stored.
66 *
67 * @return void
68 */
69 protected function initializeObject() {
70 }
71
72 /**
73 * Getter for uid
74 *
75 * @return string
76 */
77 final public function getUid() {
78 return $this->uid;
79 }
80
81 /**
82 * Reconstitutes a property. This method should only be called at reconstitution time!
83 *
84 * @param string $propertyName
85 * @param string $value
86 * @return void
87 * @internal
88 */
89 public function _reconstituteProperty($propertyName, $value) {
90 if (property_exists($this, $propertyName)) {
91 $this->$propertyName = $value;
92 return TRUE;
93 }
94 return FALSE;
95 }
96
97 /**
98 * Returns a hash map of property names and property values
99 *
100 * @return array The properties
101 * @internal
102 */
103 public function _getProperties() {
104 $properties = get_object_vars($this);
105 // unset($properties['_cleanProperties']); // TODO Check this again
106 return $properties;
107 }
108
109 /**
110 * Returns the property value of the given property name
111 *
112 * @return array The propertyName
113 * @internal
114 */
115 public function _getPropertyValue($propertyName) {
116 return $this->$propertyName;
117 }
118
119 /**
120 * Returns TRUE if the object is new (the uid was not set, yet)
121 *
122 * @return boolean
123 * @internal
124 */
125 // TODO Discuss, if this is the right way to say _isNew()
126 public function _isNew() {
127 return $this->uid === NULL;
128 }
129
130 /**
131 * Register an object's clean state, e.g. after it has been reconstituted
132 * from the database
133 *
134 * @return void
135 * @internal
136 */
137 public function _memorizeCleanState() {
138 }
139
140 /**
141 * Returns a hash map of dirty properties and $values. This is always the empty array for ValueObjects, because ValueObjects never change.
142 *
143 * @return array
144 * @internal
145 */
146 public function _getDirtyProperties() {
147 return array();
148 }
149
150 /**
151 * Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
152 *
153 * @return boolean
154 * @internal
155 */
156 public function _isDirty() {
157 return FALSE;
158 }
159
160
161 }
162 ?>