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
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<string|int, mixed>
- An array holding the internal position the object was added.
- $isModified : bool
- A flag indication if the object storage was modified after reconstitution (eg. by adding a new object)
- $positionCounter : int
- An internal var holding the count of added objects to be stored as position.
- $removedObjectsPositions : array<string|int, mixed>
- An array holding the internal position the object was added before, when it would be removed from the objectstorage
- $storage : array<string|int, mixed>
- An array holding the objects and the stored information. The key of the array items ist the spl_object_hash of the given object.
Methods
- _isDirty() : bool
- Returns TRUE if the storage was modified after reconstitution.
- _memorizeCleanState() : mixed
- Register the storage's clean state, e.g. after it has been reconstituted from the database.
- addAll() : mixed
- Adds all objects-data pairs from a different storage in the current storage.
- attach() : mixed
- Adds an object in the storage, and optionally associate it to some data.
- contains() : bool
- Checks if the storage contains a specific object.
- count() : int
- Returns the number of objects in the storage.
- current() : TEntity|null
- Returns the current storage entry.
- detach() : mixed
- 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 data, or info, associated with the object pointed by the current iterator position.
- getPosition() : int|null
- isRelationDirty() : bool
- Returns TRUE if an object is added, then removed and added at a different position
- key() : string
- Returns the index at which the iterator currently is.
- next() : mixed
- Moves to the next entry.
- offsetExists() : bool
- Checks whether an object exists in the storage.
- offsetGet() : mixed
- Returns the data associated with an object, or the object itself if an integer is passed.
- offsetSet() : mixed
- Associates data to an object in the storage. offsetSet() is an alias of attach().
- offsetUnset() : mixed
- Removes an object from the storage. offsetUnset() is an alias of detach().
- removeAll() : mixed
- Removes objects contained in another storage from the current storage.
- rewind() : mixed
- Rewinds the iterator to the first storage element.
- serialize() : mixed
- Dummy method to avoid serialization.
- setInfo() : mixed
- Associates data, or info, with the object currently pointed to by the iterator.
- toArray() : array<int, TEntity>
- Returns this object storage as an array
- unserialize() : mixed
- Dummy method to avoid unserialization.
- 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<string|int, mixed>
$addedObjectsPositions
= []
The object entry is unset when the object gets removed from the objectstorage
$isModified
A flag indication if the object storage was modified after reconstitution (eg. by adding a new object)
protected
bool
$isModified
= false
$positionCounter
An internal var holding the count of added objects to be stored as position.
protected
int
$positionCounter
= 0
It would be reset, when all objects will be removed from the objectstorage
$removedObjectsPositions
An array holding the internal position the object was added before, when it would be removed from the objectstorage
protected
array<string|int, mixed>
$removedObjectsPositions
= []
$storage
An array holding the objects and the stored information. The key of the array items ist the spl_object_hash of the given object.
protected
array<string|int, mixed>
$storage
= []
array( spl_object_hash => array( 'obj' => $object, 'inf' => $information ) )
Methods
_isDirty()
Returns TRUE if the storage was modified after reconstitution.
public
_isDirty() : bool
Return values
bool_memorizeCleanState()
Register the storage's clean state, e.g. after it has been reconstituted from the database.
public
_memorizeCleanState() : mixed
addAll()
Adds all objects-data pairs from a different storage in the current storage.
public
addAll(ObjectStorage<string|int, TEntity> $objectStorage) : mixed
Parameters
- $objectStorage : ObjectStorage<string|int, TEntity>
attach()
Adds an object in the storage, and optionally associate it to some data.
public
attach(TEntity $object[, mixed $information = null ]) : mixed
Parameters
- $object : TEntity
-
The object to add.
- $information : mixed = null
-
The data 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
boolcount()
Returns the number of objects in the storage.
public
count() : int
Attributes
- #[ReturnTypeWillChange]
Return values
int —The number of objects in the storage.
current()
Returns the current storage entry.
public
current() : TEntity|null
Attributes
- #[ReturnTypeWillChange]
Return values
TEntity|null —The object at the current iterator position.
detach()
Removes an object from the storage.
public
detach(TEntity $object) : mixed
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 data, or info, associated with the object pointed by the current iterator position.
public
getInfo() : mixed
Return values
mixed —The data associated with the current iterator position.
getPosition()
public
getPosition(mixed $object) : int|null
Parameters
- $object : mixed
Return values
int|nullisRelationDirty()
Returns TRUE if an object is added, then removed and added at a different position
public
isRelationDirty(mixed $object) : bool
Parameters
- $object : mixed
Return values
boolkey()
Returns the index at which the iterator currently is.
public
key() : string
This is different from the SplObjectStorage as the key in this implementation is the object hash (string).
Attributes
- #[ReturnTypeWillChange]
Return values
string —The index corresponding to the position of the iterator.
next()
Moves to the next entry.
public
next() : mixed
Attributes
- #[ReturnTypeWillChange]
offsetExists()
Checks whether an object exists in the storage.
public
offsetExists(TEntity|int $value) : bool
Parameters
- $value : TEntity|int
-
The object to look for, or the key in the storage.
Attributes
- #[ReturnTypeWillChange]
Return values
booloffsetGet()
Returns the data associated with an object, or the object itself if an integer is passed.
public
offsetGet(TEntity|int $value) : mixed
Parameters
- $value : TEntity|int
-
The object to look for, or its key in the storage.
Attributes
- #[ReturnTypeWillChange]
Return values
mixed —The data associated with an object in the storage, or the object itself if an integer is passed.
offsetSet()
Associates data to an object in the storage. offsetSet() is an alias of attach().
public
offsetSet(TEntity $object, mixed $information) : mixed
Parameters
- $object : TEntity
-
The object to add.
- $information : mixed
-
The data to associate with the object.
Attributes
- #[ReturnTypeWillChange]
offsetUnset()
Removes an object from the storage. offsetUnset() is an alias of detach().
public
offsetUnset(TEntity|int $value) : mixed
Parameters
- $value : TEntity|int
-
The object to remove, or its key in the storage.
Attributes
- #[ReturnTypeWillChange]
removeAll()
Removes objects contained in another storage from the current storage.
public
removeAll(ObjectStorage<string|int, TEntity> $objectStorage) : mixed
Parameters
- $objectStorage : ObjectStorage<string|int, TEntity>
-
The storage containing the elements to remove.
rewind()
Rewinds the iterator to the first storage element.
public
rewind() : mixed
Attributes
- #[ReturnTypeWillChange]
serialize()
Dummy method to avoid serialization.
public
serialize() : mixed
Tags
setInfo()
Associates data, or info, with the object currently pointed to by the iterator.
public
setInfo(mixed $data) : mixed
Parameters
- $data : mixed
toArray()
Returns this object storage as an array
public
toArray() : array<int, TEntity>
Return values
array<int, TEntity>unserialize()
Dummy method to avoid unserialization.
public
unserialize() : mixed
Tags
valid()
Checks if the array pointer of the storage points to a valid position.
public
valid() : bool
Attributes
- #[ReturnTypeWillChange]