ObjectStorage

class \TYPO3\CMS\Extbase\Persistence\ObjectStorage

Implements
Countable, Iterator, ArrayAccess, ObjectMonitoringInterface

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.

Tags

template
implements
implements

Table of Contents

Interfaces

Countable
Iterator
ArrayAccess
ObjectMonitoringInterface
An interface how to monitor changes on an object and its properties. All domain objects which should be persisted need to implement the below interface.

Properties

$addedObjectsPositions  : array
An array holding the internal position the object was added.
$isModified  : bool
A flag indication if the object storage was modified after reconstitution (e.g., by adding a new object)
$positionCounter  : int
An internal variable holding the count of added objects to be stored as position.
$removedObjectsPositions  : array
An array holding the internal position the object was added before, when it would be removed from the object storage.
$storage  : array
An array holding the objects and the stored information. The key of the array items ist the spl_object_id of the given object.

Methods

__serialize()  : array
A lazy storage is explicitly initialized before its state is collected: The engine's serializer must never trigger the initialization of a lazy object during its traversal, as that corrupts back references within the serialized payload.
__unserialize()  : void
The internal state is rebuilt from the plain object list, so all spl_object_id() based keys refer to the objects created by the current unserialize() call. This keeps detach(), contains() and offsetGet() working on an unserialized storage.
_isDirty()  : bool
Returns `true` if the storage was modified after reconstitution.
_memorizeCleanState()  : void
Register the storage's clean state, e.g., after it has been reconstituted from the database.
addAll()  : void
Adds all object-information pairs from a different storage in the current storage.
attach()  : void
Adds an object in the storage, and optionally associate it to some information.
contains()  : bool
Checks if the storage contains a specific object.
count()  : 0|positive-int
Returns the number of objects in the storage.
current()  : TEntity|null
Returns the current storage entry.
detach()  : void
Removes an object from the storage.
getArray()  : array<int, TEntity>
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 the `children` property which is an `ObjectStorage`.
getInfo()  : mixed
Returns the information associated with the object pointed by the current iterator position.
getPosition()  : int|null
isRelationDirty()  : bool
Returns `true` if an object was added, then removed and added at a different position.
key()  : string
Returns the index at which the iterator currently is.
next()  : void
Moves to the next entry.
offsetExists()  : bool
Checks whether an object exists in the storage.
offsetGet()  : mixed
Returns the information associated with an object, or the object itself if an integer is passed.
offsetSet()  : void
Associates information to an object in the storage. `offsetSet()` is an alias of `attach()`.
offsetUnset()  : void
Removes an object from the storage. `offsetUnset()` is an alias of `detach()`.
removeAll()  : void
Removes objects contained in another storage from the current storage.
rewind()  : void
Rewinds the iterator to the first storage element.
setInfo()  : void
Associates information with the object currently pointed to by the iterator.
toArray()  : array<int, TEntity>
Returns this object storage as an array.
valid()  : bool
Checks if the array pointer of the storage points to a valid position.

Properties

$addedObjectsPositions

An array holding the internal position the object was added.

protected array $addedObjectsPositions = []

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

$isModified

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

protected bool $isModified = false

$positionCounter

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

protected int $positionCounter = 0

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

$removedObjectsPositions

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

protected array $removedObjectsPositions = []

$storage

An array holding the objects and the stored information. The key of the array items ist the spl_object_id of the given object.

protected array $storage = []
[
  'spl_object_id' => [
    'obj' => $object,
    'inf' => $information,
  ],
]

Methods

__serialize()

A lazy storage is explicitly initialized before its state is collected: The engine's serializer must never trigger the initialization of a lazy object during its traversal, as that corrupts back references within the serialized payload.

public __serialize() : array

The contained objects are stored as a plain list, since the spl_object_id() based keys of the internal arrays are only valid for the current process.

Return values

array

__unserialize()

The internal state is rebuilt from the plain object list, so all spl_object_id() based keys refer to the objects created by the current unserialize() call. This keeps detach(), contains() and offsetGet() working on an unserialized storage.

public __unserialize(array $data) : void

Parameters

$data : array

_isDirty()

Returns `true` if the storage was modified after reconstitution.

public _isDirty([non-empty-string|null $propertyName = null ]) : bool

Parameters

$propertyName : non-empty-string|null = null

Return values

bool

_memorizeCleanState()

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

public _memorizeCleanState([non-empty-string|null $propertyName = null ]) : void

Parameters

$propertyName : non-empty-string|null = null

addAll()

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

public addAll(ObjectStorage<string|int, TEntity> $storage) : void

Parameters

$storage : ObjectStorage<string|int, TEntity>

attach()

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

public attach(TEntity $object[, mixed $information = null ]) : void

Parameters

$object : TEntity

The object to add.

$information : mixed = null

The information to associate with the object.

contains()

Checks if the storage contains a specific object.

public contains(TEntity $object) : bool

Parameters

$object : TEntity

The object to look for.

Return values

bool

count()

Returns the number of objects in the storage.

public count() : 0|positive-int

Return values

0|positive-int —

The number of objects in the storage.

current()

Returns the current storage entry.

public current() : TEntity|null

Return values

TEntity|null —

The object at the current iterator position.

detach()

Removes an object from the storage.

public detach(TEntity $object) : void

Parameters

$object : TEntity

The object to remove.

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 the `children` property which is an `ObjectStorage`.

public getArray() : array<int, TEntity>

Return values

array<int, TEntity>

getInfo()

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

public getInfo() : mixed

Return values

mixed —

The information associated with the current iterator position.

getPosition()

public getPosition(object $object) : int|null

Parameters

$object : object

Return values

int|null

isRelationDirty()

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

public isRelationDirty(object $object) : bool

Parameters

$object : object

Return values

bool

key()

Returns the index at which the iterator currently is.

public key() : string

This is different from SplObjectStorage as the key in this implementation is derived from the object id and returned as string.

Return values

string —

The index corresponding to the position of the iterator.

next()

Moves to the next entry.

public next() : void

offsetExists()

Checks whether an object exists in the storage.

public offsetExists(TEntity|int|string $value) : bool

Parameters

$value : TEntity|int|string

The object to look for, or the key in the storage.

Return values

bool

offsetGet()

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

public offsetGet(TEntity|int|string $value) : mixed

Parameters

$value : TEntity|int|string

The object to look for, or its key in the storage.

Return values

mixed —

The information associated with an object in the storage, or the object itself if an integer is passed.

offsetSet()

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

public offsetSet(TEntity|string|null $object, mixed $information) : void

Parameters

$object : TEntity|string|null

The object to add.

$information : mixed

The information to associate with the object.

offsetUnset()

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

public offsetUnset(TEntity|int|string $value) : void

Parameters

$value : TEntity|int|string

The object to remove, or its key in the storage.

removeAll()

Removes objects contained in another storage from the current storage.

public removeAll(ObjectStorage<string|int, TEntity> $storage) : void

Parameters

$storage : ObjectStorage<string|int, TEntity>

The storage containing the elements to remove.

rewind()

Rewinds the iterator to the first storage element.

public rewind() : void

setInfo()

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

public setInfo(mixed $information) : void

Parameters

$information : mixed

toArray()

Returns this object storage as an array.

public toArray() : array<int, TEntity>

Return values

array<int, TEntity>

valid()

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

public valid() : bool

Return values

bool
On this page