LazyObjectStorage

class \TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage

Extends
ObjectStorage
Implements
LoadingStrategyInterface

A proxy that can replace any object and replaces itself in its parent on the first access (`call`, `get`, `set`, `isset`, `unset`).

Deprecated

since TYPO3 v15.0, will be removed in TYPO3 v16.0. Lazy-loading object storages are created as native PHP lazy ghost instances of ObjectStorage by the DataMapper instead.

Tags

template
extends

Table of Contents

Interfaces

LoadingStrategyInterface
An interface for the lazy loading strategies.

Properties

$addedObjectsPositions  : array
An array holding the internal position the object was added.
$dataMapper  : DataMapper
$fieldValue  : mixed
The raw field value.
$isInitialized  : bool
$isModified  : bool
A flag indication if the object storage was modified after reconstitution (e.g., by adding a new object)
$parentObject  : DomainObjectInterface
The object this property is contained in.
$positionCounter  : int
An internal variable holding the count of added objects to be stored as position.
$propertyName  : string
The name of the property represented by this proxy.
$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

__construct()  : mixed
__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
Counts the elements in the storage array
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
isInitialized()  : bool
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.
initialize()  : void
Lazily initializes the object storage.
isStorageAlreadyMemorizedInParentCleanState()  : bool

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.

$fieldValue

The raw field value.

protected mixed $fieldValue

$isInitialized

protected bool $isInitialized = false

$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.

$propertyName

The name of the property represented by this proxy.

protected string $propertyName

$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

__construct()

public __construct(TEntity $parentObject, string $propertyName, mixed $fieldValue[, DataMapper|null $dataMapper = null ]) : mixed

Parameters

$parentObject : TEntity

The object instance this proxy is part of

$propertyName : string

The name of the proxied property in its parent

$fieldValue : mixed

The raw field value.

$dataMapper : DataMapper|null = null

__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 $storage) : void

Parameters

$storage : ObjectStorage

Tags

see

ObjectStorage::addAll

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.

Tags

see

ObjectStorage::attach

contains()

Checks if the storage contains a specific object.

public contains(TEntity $object) : bool

Parameters

$object : TEntity

The object to look for.

Tags

see

ObjectStorage::contains

Return values

bool

count()

Counts the elements in the storage array

public count() : 0|positive-int

Tags

throws
Exception

Return values

0|positive-int —

The number of objects in the storage.

current()

Returns the current storage entry.

public current() : TEntity|null

Tags

see

ObjectStorage::current

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.

Tags

see

ObjectStorage::detach

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(mixed $object) : int|null

Parameters

$object : mixed

Return values

int|null

isInitialized()

public isInitialized() : bool

Return values

bool

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

Tags

see

ObjectStorage::key

Return values

string —

The index corresponding to the position of the iterator.

next()

Moves to the next entry.

public next() : void

Tags

see

ObjectStorage::next

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.

Tags

see

ObjectStorage::offsetExists

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.

Tags

see

ObjectStorage::offsetGet

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.

Tags

see

ObjectStorage::offsetSet

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.

Tags

see

ObjectStorage::offsetUnset

removeAll()

Removes objects contained in another storage from the current storage.

public removeAll(ObjectStorage $storage) : void

Parameters

$storage : ObjectStorage

The storage containing the elements to remove.

Tags

see

ObjectStorage::removeAll

rewind()

Rewinds the iterator to the first storage element.

public rewind() : void

Tags

see

ObjectStorage::rewind

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>

Tags

see

ObjectStorage::toArray

Return values

array<int, TEntity>

valid()

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

public valid() : bool

Tags

see

ObjectStorage::valid

Return values

bool

initialize()

Lazily initializes the object storage.

protected initialize() : void

isStorageAlreadyMemorizedInParentCleanState()

protected isStorageAlreadyMemorizedInParentCleanState() : bool

Return values

bool
On this page