TYPO3 CMS  TYPO3_6-2
AbstractDomainObject.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $uid;
27 
31  protected $_localizedUid;
32 
36  protected $_languageUid;
37 
41  protected $_versionedUid;
42 
46  protected $pid;
47 
53  private $_isClone = FALSE;
54 
58  private $_cleanProperties = array();
59 
67  public function __wakeup() {
68  }
69 
70  public function initializeObject() {
71  }
72 
78  public function getUid() {
79  if ($this->uid !== NULL) {
80  return (int)$this->uid;
81  } else {
82  return NULL;
83  }
84  }
85 
92  public function setPid($pid) {
93  if ($pid === NULL) {
94  $this->pid = NULL;
95  } else {
96  $this->pid = (int)$pid;
97  }
98  }
99 
105  public function getPid() {
106  if ($this->pid === NULL) {
107  return NULL;
108  } else {
109  return (int)$this->pid;
110  }
111  }
112 
120  public function _setProperty($propertyName, $propertyValue) {
121  if ($this->_hasProperty($propertyName)) {
122  $this->{$propertyName} = $propertyValue;
123  return TRUE;
124  }
125  return FALSE;
126  }
127 
134  public function _getProperty($propertyName) {
135  return $this->{$propertyName};
136  }
137 
143  public function _getProperties() {
144  $properties = get_object_vars($this);
145  foreach ($properties as $propertyName => $propertyValue) {
146  if ($propertyName[0] === '_') {
147  unset($properties[$propertyName]);
148  }
149  }
150  return $properties;
151  }
152 
159  public function _hasProperty($propertyName) {
160  return property_exists($this, $propertyName);
161  }
162 
168  public function _isNew() {
169  return $this->uid === NULL;
170  }
171 
179  public function _memorizeCleanState($propertyName = NULL) {
180  if ($propertyName !== NULL) {
181  $this->_memorizePropertyCleanState($propertyName);
182  } else {
183  $this->_cleanProperties = array();
184  $properties = get_object_vars($this);
185  foreach ($properties as $propertyName => $propertyValue) {
186  if ($propertyName[0] === '_') {
187  continue;
188  }
189  // Do not memorize "internal" properties
190  $this->_memorizePropertyCleanState($propertyName);
191  }
192  }
193  }
194 
202  public function _memorizePropertyCleanState($propertyName) {
203  $propertyValue = $this->{$propertyName};
204  if (is_object($propertyValue)) {
205  $this->_cleanProperties[$propertyName] = clone $propertyValue;
206  // We need to make sure the clone and the original object
207  // are identical when compared with == (see _isDirty()).
208  // After the cloning, the Domain Object will have the property
209  // "isClone" set to TRUE, so we manually have to set it to FALSE
210  // again. Possible fix: Somehow get rid of the "isClone" property,
211  // which is currently needed in Fluid.
212  if ($propertyValue instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject) {
213  $this->_cleanProperties[$propertyName]->_setClone(FALSE);
214  }
215  } else {
216  $this->_cleanProperties[$propertyName] = $propertyValue;
217  }
218  }
219 
225  public function _getCleanProperties() {
227  }
228 
236  public function _getCleanProperty($propertyName) {
237  return isset($this->_cleanProperties[$propertyName]) ? $this->_cleanProperties[$propertyName] : NULL;
238  }
239 
247  public function _isDirty($propertyName = NULL) {
248  if ($this->uid !== NULL && $this->_getCleanProperty('uid') !== NULL && $this->uid != $this->_getCleanProperty('uid')) {
249  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\TooDirtyException('The uid "' . $this->uid . '" has been modified, that is simply too much.', 1222871239);
250  }
251 
252  if ($propertyName === NULL) {
253  foreach ($this->_getCleanProperties() as $propertyName => $cleanPropertyValue) {
254  if ($this->isPropertyDirty($cleanPropertyValue, $this->{$propertyName}) === TRUE) {
255  return TRUE;
256  }
257  }
258  } else {
259  if ($this->isPropertyDirty($this->_getCleanProperty($propertyName), $this->{$propertyName}) === TRUE) {
260  return TRUE;
261  }
262  }
263  return FALSE;
264  }
265 
273  protected function isPropertyDirty($previousValue, $currentValue) {
274  // In case it is an object and it implements the ObjectMonitoringInterface, we call _isDirty() instead of a simple comparison of objects.
275  // We do this, because if the object itself contains a lazy loaded property, the comparison of the objects might fail even if the object didn't change
276  if (is_object($currentValue)) {
277  if ($currentValue instanceof DomainObjectInterface) {
278  $result = !is_object($previousValue) || get_class($previousValue) !== get_class($currentValue) || $currentValue->getUid() !== $previousValue->getUid();
279  } elseif ($currentValue instanceof \TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface) {
280  $result = !is_object($previousValue) || $currentValue->_isDirty() || get_class($previousValue) !== get_class($currentValue);
281  } else {
282  // For all other objects we do only a simple comparison (!=) as we want cloned objects to return the same values.
283  $result = $previousValue != $currentValue;
284  }
285  } else {
286  $result = $previousValue !== $currentValue;
287  }
288  return $result;
289  }
290 
296  public function _isClone() {
297  return $this->_isClone;
298  }
299 
308  public function _setClone($clone) {
309  $this->_isClone = (boolean) $clone;
310  }
311 
317  public function __clone() {
318  $this->_isClone = TRUE;
319  }
320 
326  public function __toString() {
327  return get_class($this) . ':' . (string) $this->uid;
328  }
329 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.