TYPO3 CMS  TYPO3_6-2
LazyObjectStorage.php
Go to the documentation of this file.
1 <?php
3 
21 
30  private $warning = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage. To retrieve the first result, you can use the rewind() and current() methods.';
31 
36  protected $dataMapper;
37 
43  protected $parentObject;
44 
50  protected $propertyName;
51 
57  protected $fieldValue;
58 
62  protected $isInitialized = FALSE;
63 
69  public function isInitialized() {
70  return $this->isInitialized;
71  }
72 
81  $this->parentObject = $parentObject;
82  $this->propertyName = $propertyName;
83  $this->fieldValue = $fieldValue;
84  reset($this->storage);
85  }
86 
92  protected function initialize() {
93  if (!$this->isInitialized) {
94  $this->isInitialized = TRUE;
95  $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE);
96  foreach ($objects as $object) {
97  parent::attach($object);
98  }
99  $this->_memorizeCleanState();
101  $this->parentObject->_memorizeCleanState($this->propertyName);
102  }
103  }
104  }
105 
110  return $this->parentObject->_getCleanProperty($this->propertyName) === $this;
111  }
112 
113  // Delegation to the ObjectStorage methods below
119  public function addAll($storage) {
120  $this->initialize();
121  parent::addAll($storage);
122  }
123 
130  public function attach($object, $data = NULL) {
131  $this->initialize();
132  parent::attach($object, $data);
133  }
134 
141  public function contains($object) {
142  $this->initialize();
143  return parent::contains($object);
144  }
145 
152  public function count() {
153  $columnMap = $this->dataMapper->getDataMap(get_class($this->parentObject))->getColumnMap($this->propertyName);
154  $numberOfElements = NULL;
155  if (!$this->isInitialized && $columnMap->getTypeOfRelation() === Mapper\ColumnMap::RELATION_HAS_MANY) {
156  $numberOfElements = $this->dataMapper->countRelated($this->parentObject, $this->propertyName, $this->fieldValue);
157  } else {
158  $this->initialize();
159  $numberOfElements = count($this->storage);
160  }
161  if (is_null($numberOfElements)) {
162  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('The number of elements could not be determined.', 1252514486);
163  }
164  return $numberOfElements;
165  }
166 
172  public function current() {
173  $this->initialize();
174  return parent::current();
175  }
176 
182  public function detach($object) {
183  $this->initialize();
184  parent::detach($object);
185  }
186 
192  public function key() {
193  $this->initialize();
194  return parent::key();
195  }
196 
200  public function next() {
201  $this->initialize();
202  parent::next();
203  }
204 
211  public function offsetExists($object) {
212  $this->initialize();
213  return parent::offsetExists($object);
214  }
215 
222  public function offsetGet($object) {
223  $this->initialize();
224  return parent::offsetGet($object);
225  }
226 
233  public function offsetSet($object, $info) {
234  $this->initialize();
235  parent::offsetSet($object, $info);
236  }
237 
244  public function offsetUnset($object) {
245  $this->initialize();
246  parent::offsetUnset($object);
247  }
248 
255  public function removeAll($storage) {
256  $this->initialize();
257  parent::removeAll($storage);
258  }
259 
263  public function rewind() {
264  $this->initialize();
265  parent::rewind();
266  }
267 
273  public function valid() {
274  $this->initialize();
275  return parent::valid();
276  }
277 
283  public function toArray() {
284  $this->initialize();
285  return parent::toArray();
286  }
287 
292  public function getPosition($object) {
293  $this->initialize();
294  return parent::getPosition($object);
295  }
296 }
__construct($parentObject, $propertyName, $fieldValue)