‪TYPO3CMS  ‪main
TYPO3\CMS\Extbase\Persistence\ObjectStorage Class Reference
Inheritance diagram for TYPO3\CMS\Extbase\Persistence\ObjectStorage:
TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage

Public Member Functions

 rewind ()
 
 valid ()
 
string key ()
 
TEntity null current ()
 
 next ()
 
positive int count ()
 
 offsetSet (mixed $object, mixed $information)
 
 offsetExists (mixed $value)
 
 offsetUnset (mixed $value)
 
mixed offsetGet (mixed $value)
 
 contains (object $object)
 
 attach (object $object, mixed $information=null)
 
 detach (object $object)
 
mixed getInfo ()
 
 setInfo (mixed $information)
 
 addAll (ObjectStorage $storage)
 
 removeAll (ObjectStorage $storage)
 
list< TEntity > toArray ()
 
list< TEntity > getArray ()
 
 _memorizeCleanState (?string $propertyName=null)
 
 _isDirty (?string $propertyName=null)
 
 isRelationDirty (object $object)
 
 getPosition (object $object)
 

Protected Attributes

array $storage = []
 
bool $isModified = false
 
array $addedObjectsPositions = []
 
array $removedObjectsPositions = []
 
int $positionCounter = 0
 

Private Attributes

string $warning = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage. To retrieve the first result, you can use the rewind() and current() methods.'
 

Detailed Description

The storage for objects. It ensures the uniqueness of an object in the storage. It's a remake of the SplObjectStorage introduced in PHP 5.3.

Opposed to the SplObjectStorage, the ObjectStorage does not implement the Serializable interface.

@template TEntity of object <string, TEntity> <string, TEntity>

Definition at line 33 of file ObjectStorage.php.

Member Function Documentation

◆ _isDirty()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::_isDirty ( ?string  $propertyName = null)

Returns true if the storage was modified after reconstitution.

Parameters
non-empty-string | null$propertyName

Implements TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.

Definition at line 328 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Utility\DebuggerUtility\renderHeader().

◆ _memorizeCleanState()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::_memorizeCleanState ( ?string  $propertyName = null)

Register the storage's clean state, e.g., after it has been reconstituted from the database.

Parameters
non-empty-string | null$propertyName

Implements TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.

Definition at line 318 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\initialize().

◆ addAll()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::addAll ( ObjectStorage  $storage)

Adds all object-information pairs from a different storage in the current storage.

Parameters
ObjectStorage<TEntity>‪$storage

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 267 of file ObjectStorage.php.

◆ attach()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::attach ( object  $object,
mixed  $information = null 
)

Adds an object in the storage, and optionally associate it to some information.

Parameters
TEntity$object‪The object to add.
mixed$information‪The information to associate with the object.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 225 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\addAll().

◆ contains()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::contains ( object  $object)

Checks if the storage contains a specific object.

Parameters
TEntity$object‪The object to look for.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 214 of file ObjectStorage.php.

◆ count()

positive int TYPO3\CMS\Extbase\Persistence\ObjectStorage::count ( )

Returns the number of objects in the storage.

Returns
‪0|positive-int The number of objects in the storage.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 137 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\count().

◆ current()

◆ detach()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::detach ( object  $object)

Removes an object from the storage.

Parameters
TEntity$object‪The object to remove.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 235 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\removeAll().

◆ getArray()

list<TEntity> TYPO3\CMS\Extbase\Persistence\ObjectStorage::getArray ( )

Alias of toArray which allows that method to be used from contexts which support for example dotted paths, e.g., ‘ObjectAccess::getPropertyPath($object, 'children.array.123’) to get exactly the 123rd item in thechildrenproperty which is anObjectStorage`.

Returns
‪list<TEntity>

Definition at line 308 of file ObjectStorage.php.

◆ getInfo()

mixed TYPO3\CMS\Extbase\Persistence\ObjectStorage::getInfo ( )

Returns the information associated with the object pointed by the current iterator position.

Returns
‪mixed The information associated with the current iterator position.

Definition at line 245 of file ObjectStorage.php.

◆ getPosition()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::getPosition ( object  $object)

◆ isRelationDirty()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::isRelationDirty ( object  $object)

Returns true if an object was added, then removed and added at a different position.

Definition at line 336 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\Generic\Backend\persistObjectStorage().

◆ key()

string TYPO3\CMS\Extbase\Persistence\ObjectStorage::key ( )

Returns the index at which the iterator currently is.

This is different from SplObjectStorage as the key in this implementation is the object hash (string).

Returns
‪string The index corresponding to the position of the iterator.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 108 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\key(), and TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\setInfo().

◆ next()

◆ offsetExists()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetExists ( mixed  $value)

Checks whether an object exists in the storage.

Parameters
TEntity | int | string$value‪The object to look for, or the key in the storage.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 162 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\contains().

◆ offsetGet()

mixed TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetGet ( mixed  $value)

Returns the information associated with an object, or the object itself if an integer is passed.

Parameters
TEntity | int | string$value‪The object to look for, or its key in the storage.
Returns
‪mixed The information associated with an object in the storage, or the object itself if an integer is passed.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 199 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\offsetUnset().

◆ offsetSet()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet ( mixed  $object,
mixed  $information 
)

Associates information to an object in the storage. offsetSet() is an alias of attach().

Parameters
TEntity | string | null$object‪The object to add.
mixed$information‪The information to associate with the object.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 148 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\attach().

◆ offsetUnset()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetUnset ( mixed  $value)

Removes an object from the storage. offsetUnset() is an alias of detach().

Parameters
TEntity | int | string$value‪The object to remove, or its key in the storage.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 173 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\detach().

◆ removeAll()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::removeAll ( ObjectStorage  $storage)

Removes objects contained in another storage from the current storage.

Parameters
ObjectStorage<TEntity>‪$storage The storage containing the elements to remove.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 279 of file ObjectStorage.php.

Referenced by TYPO3Tests\BlogExample\Domain\Model\Post\removeAllAdditionalComments(), TYPO3Tests\BlogExample\Domain\Model\Post\removeAllComments(), and TYPO3Tests\BlogExample\Domain\Model\Post\removeAllRelatedPosts().

◆ rewind()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::rewind ( )

Rewinds the iterator to the first storage element.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 88 of file ObjectStorage.php.

◆ setInfo()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::setInfo ( mixed  $information)

Associates information with the object currently pointed to by the iterator.

Definition at line 255 of file ObjectStorage.php.

◆ toArray()

list<TEntity> TYPO3\CMS\Extbase\Persistence\ObjectStorage::toArray ( )

◆ valid()

TYPO3\CMS\Extbase\Persistence\ObjectStorage::valid ( )

Checks if the array pointer of the storage points to a valid position.

Reimplemented in TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage.

Definition at line 96 of file ObjectStorage.php.

Member Data Documentation

◆ $addedObjectsPositions

array TYPO3\CMS\Extbase\Persistence\ObjectStorage::$addedObjectsPositions = []
protected

An array holding the internal position the object was added.

The object entry is unset when the object gets removed from the object storage.

Definition at line 70 of file ObjectStorage.php.

◆ $isModified

bool TYPO3\CMS\Extbase\Persistence\ObjectStorage::$isModified = false
protected

A flag indication if the object storage was modified after reconstitution (e.g., by adding a new object)

Definition at line 63 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\_isDirty().

◆ $positionCounter

int TYPO3\CMS\Extbase\Persistence\ObjectStorage::$positionCounter = 0
protected

An internal variable holding the count of added objects to be stored as position.

It will be reset when all objects are be removed from the object storage.

Definition at line 83 of file ObjectStorage.php.

Referenced by TYPO3\CMS\Extbase\Persistence\ObjectStorage< TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\Property\DummyEntityWithoutTypeDeclarations >\offsetSet().

◆ $removedObjectsPositions

array TYPO3\CMS\Extbase\Persistence\ObjectStorage::$removedObjectsPositions = []
protected

An array holding the internal position the object was added before, when it would be removed from the object storage.

Definition at line 76 of file ObjectStorage.php.

◆ $storage

◆ $warning

string TYPO3\CMS\Extbase\Persistence\ObjectStorage::$warning = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage. To retrieve the first result, you can use the rewind() and current() methods.'
private

This field is only needed to make debugging easier:

If you call current() on a class that implements Iterator, PHP will return the first field of the object instead of calling the current() method of the interface.

We use this unusual behavior of PHP to return the warning below in this case.

Definition at line 43 of file ObjectStorage.php.