[TASK] Extbase: Removed Extbase_Exception and renamed everything to use Extbase_MVC_E...
[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 * All Model domain objects need to inherit from either AbstractEntity or AbstractValueObject, as this provides important framework information.
29 *
30 * @package Extbase
31 * @subpackage DomainObject
32 * @version $ID:$
33 */
34 abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbase_DomainObject_DomainObjectInterface {
35
36 /**
37 * @var string The uid
38 */
39 protected $uid;
40
41 /**
42 * The generic constructor. If you want to implement your own __constructor() method in your Domain Object you have to call
43 * $this->initializeObject() in the first line of your constructor.
44 *
45 * @var array
46 */
47 public function __construct() {
48 $this->initializeObject();
49 }
50
51 /**
52 * This is the magic __wakeup() method. It's invoked by the unserialize statement in the reconstitution process
53 * of the object. If you want to implement your own __wakeup() method in your Domain Object you have to call
54 * parent::__wakeup() first!
55 *
56 * @return void
57 */
58 public function __wakeup() {
59 $this->initializeObject();
60 }
61
62 /**
63 * A template method to initialize an object. This can be used to manipulate the object after
64 * reconstitution and before the clean state of it's properties is stored.
65 *
66 * @return void
67 */
68 protected function initializeObject() {
69 }
70
71 /**
72 * Getter for uid.
73 *
74 * @return int the uid or NULL if none set yet.
75 */
76 final public function getUid() {
77 return ($this->uid === NULL ? NULL : (int)$this->uid);
78 }
79
80 /**
81 * Reconstitutes a property. Only for internal use.
82 *
83 * @param string $propertyName
84 * @param string $value
85 * @return void
86 */
87 public function _setProperty($propertyName, $propertyValue) {
88 if (property_exists($this, $propertyName)) {
89 $this->$propertyName = $propertyValue;
90 return TRUE;
91 }
92 return FALSE;
93 }
94
95 /**
96 * Returns the property value of the given property name. Only for internal use.
97 *
98 * @return mixed The propertyValue
99 */
100 public function _getProperty($propertyName) {
101 return $this->$propertyName;
102 }
103
104 /**
105 * Returns a hash map of property names and property values. Only for internal use.
106 *
107 * @return array The properties
108 */
109 public function _getProperties() {
110 $properties = get_object_vars($this);
111 unset($properties['_cleanProperties']);
112 return $properties;
113 }
114
115 /**
116 * Returns TRUE if the object is new (the uid was not set, yet). Only for internal use
117 *
118 * @return boolean
119 */
120 public function _isNew() {
121 return $this->uid === NULL;
122 }
123
124 /**
125 * Register an object's clean state, e.g. after it has been reconstituted
126 * from the database
127 *
128 * @return void
129 */
130 public function _memorizeCleanState() {
131 }
132
133 /**
134 * Returns a hash map of dirty properties and $values. This is always the empty array for ValueObjects, because ValueObjects never change.
135 *
136 * @return array
137 */
138 public function _getDirtyProperties() {
139 return array();
140 }
141
142 /**
143 * Returns TRUE if the properties were modified after reconstitution. However, value objects can be never updated.
144 *
145 * @return boolean
146 */
147 public function _isDirty() {
148 return FALSE;
149 }
150 }
151 ?>