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 Extbase
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 * @internal
56 */
57 public function __wakeup() {
58 $this->initializeObject();
59 }
60
61 /**
62 * A template method to initialize an object. This can be used to manipulate the object after
63 * reconstitution and before the clean state of it's properties is stored.
64 *
65 * @return void
66 */
67 protected function initializeObject() {
68 }
69
70 /**
71 * Getter for uid
72 *
73 * @return int
74 */
75 final public function getUid() {
76 return (int)$this->uid;
77 }
78
79 /**
80 * Getter for the identifier
81 *
82 * @return int
83 */
84 final public function getIdentifier() {
85 return (int)$this->uid;
86 }
87
88 /**
89 * Reconstitutes a property. Only for internal use.
90 *
91 * @param string $propertyName
92 * @param string $value
93 * @return void
94 * @internal
95 */
96 public function _setProperty($propertyName, $propertyValue) {
97 if (property_exists($this, $propertyName)) {
98 $this->$propertyName = $propertyValue;
99 return TRUE;
100 }
101 return FALSE;
102 }
103
104 /**
105 * Returns the property value of the given property name. Only for internal use.
106 *
107 * @return mixed The propertyValue
108 * @internal
109 */
110 public function _getProperty($propertyName) {
111 return $this->$propertyName;
112 }
113
114 /**
115 * Returns a hash map of property names and property values. Only for internal use.
116 *
117 * @return array The properties
118 * @internal
119 */
120 public function _getProperties() {
121 $properties = get_object_vars($this);
122 unset($properties['_cleanProperties']);
123 return $properties;
124 }
125
126 /**
127 * Returns TRUE if the object is new (the uid was not set, yet). Only for internal use
128 *
129 * @return boolean
130 * @internal
131 */
132 public function _isNew() {
133 return $this->uid === NULL;
134 }
135
136 /**
137 * Register an object's clean state, e.g. after it has been reconstituted
138 * from the database
139 *
140 * @return void
141 * @internal
142 */
143 public function _memorizeCleanState() {
144 }
145
146 /**
147 * Returns a hash map of dirty properties and $values. This is always the empty array for ValueObjects, because ValueObjects never change.
148 *
149 * @return array
150 * @internal
151 */
152 public function _getDirtyProperties() {
153 return array();
154 }
155
156 /**
157 * Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
158 *
159 * @return boolean
160 * @internal
161 */
162 public function _isDirty() {
163 return FALSE;
164 }
165 }
166 ?>