class PersistenceManager extends AbstractPersistenceManager (View source)

deprecated since Flow 6.0

The generic Flow Persistence Manager

Properties

protected array $settings from  AbstractPersistenceManager
protected array $newObjects from  AbstractPersistenceManager
protected bool $hasUnpersistedChanges from  AbstractPersistenceManager
protected AllowedObjectsContainer $allowedObjects from  AbstractPersistenceManager
protected SplObjectStorage $changedObjects
protected SplObjectStorage $addedObjects
protected SplObjectStorage $removedObjects
protected QueryFactoryInterface $queryFactory
protected DataMapper $dataMapper
protected BackendInterface $backend
protected Session $persistenceSession

Methods

void
injectSettings(array $settings)

Injects the Flow settings, the persistence part is kept for further use.

void
clearState()

Clears the in-memory state of the persistence.

void
registerNewObject(PersistenceMagicInterface $object)

Registers an object which has been created or cloned during this request.

void
whitelistObject(object $object) deprecated

Adds the given object to a list of allowed objects which may be persisted even if the current HTTP request is considered a "safe" request.

void
allowObject(object $object)

Adds the given object to a list of allowed objects which may be persisted even if the current HTTP request is considered a "safe" request.

array
convertObjectToIdentityArray(object $object)

Converts the given object into an array containing the identity of the domain object.

array
convertObjectsToIdentityArrays(array $array)

Recursively iterates through the given array and turns objects into an arrays containing the identity of the domain object.

bool
hasUnpersistedChanges()

Gives feedback if the persistence Manager has unpersisted changes.

__construct()

Create new instance

void
injectQueryFactory(QueryFactoryInterface $queryFactory)

Injects a QueryFactory instance

void
injectDataMapper(DataMapper $dataMapper)

Injects the data mapper

void
injectBackend(BackendInterface $backend)

Injects the backend to use

void
injectPersistenceSession(Session $persistenceSession)

Injects the persistence session

void
initializeObject()

Initializes the persistence manager

int
getObjectCountByQuery(QueryInterface $query)

Returns the number of records matching the query.

array
getObjectDataByQuery(QueryInterface $query)

Returns the object data matching the $query.

void
persistAll(bool $onlyAllowedObjects = false)

Commits new objects and changes to objects in the current persistence session into the backend

bool
isNewObject(object $object)

Checks if the given object has ever been persisted.

mixed
getIdentifierByObject(object $object)

Returns the (internal) identifier for the object, if it is known to the backend. Otherwise NULL is returned.

object|null
getObjectByIdentifier(mixed $identifier, string $objectType = null, bool $useLazyLoading = false)

Returns the object with the (internal) identifier, if it is known to the backend. Otherwise NULL is returned.

object
getObjectDataByIdentifier(string $identifier, string $objectType = null)

Returns the object data for the (internal) identifier, if it is known to the backend. Otherwise false is returned.

createQueryForType(string $type)

Return a query object for the given type.

void
add(object $object)

Adds an object to the persistence.

void
remove(object $object)

Removes an object to the persistence.

void
update(object $object)

Update an object in the persistence.

bool
isConnected()

Returns true, if an active connection to the persistence backend has been established, e.g. entities can be persisted.

void
throwExceptionIfObjectIsNotAllowed(object $object)

Checks if the given object is allowed and if not, throws an exception

void
emitAllObjectsPersisted()

Signals that all persistAll() has been executed successfully.

void
tearDown()

Tear down the persistence

Details

void injectSettings(array $settings)

Injects the Flow settings, the persistence part is kept for further use.

Parameters

array $settings

Return Value

void

void clearState()

Clears the in-memory state of the persistence.

Managed instances become detached, any fetches will return data directly from the persistence "backend". It will also forget about new objects.

Return Value

void

void registerNewObject(PersistenceMagicInterface $object)

Registers an object which has been created or cloned during this request.

The given object must contain the Persistence_Object_Identifier property, thus the PersistenceMagicInterface type hint. A "new" object does not necessarily have to be known by any repository or be persisted in the end.

Objects registered with this method must be known to the getObjectByIdentifier() method.

Parameters

PersistenceMagicInterface $object

The new object to register

Return Value

void

void whitelistObject(object $object) deprecated

deprecated Use allowObject() instead. See https://github.com/neos/flow-development-collection/pull/2024

Adds the given object to a list of allowed objects which may be persisted even if the current HTTP request is considered a "safe" request.

Parameters

object $object

The object

Return Value

void

void allowObject(object $object)

Adds the given object to a list of allowed objects which may be persisted even if the current HTTP request is considered a "safe" request.

Parameters

object $object

The object

Return Value

void

array convertObjectToIdentityArray(object $object)

Converts the given object into an array containing the identity of the domain object.

Parameters

object $object

The object to be converted

Return Value

array

The identity array in the format array('__identity' => '...')

Exceptions

UnknownObjectException

array convertObjectsToIdentityArrays(array $array)

Recursively iterates through the given array and turns objects into an arrays containing the identity of the domain object.

Parameters

array $array

The array to be iterated over

Return Value

array

The modified array without objects

Exceptions

UnknownObjectException

bool hasUnpersistedChanges()

Gives feedback if the persistence Manager has unpersisted changes.

This is primarily used to inform the user if he tries to save data in an unsafe request.

Return Value

bool

__construct()

Create new instance

void injectQueryFactory(QueryFactoryInterface $queryFactory)

Injects a QueryFactory instance

Parameters

QueryFactoryInterface $queryFactory

Return Value

void

void injectDataMapper(DataMapper $dataMapper)

Injects the data mapper

Parameters

DataMapper $dataMapper

Return Value

void

void injectBackend(BackendInterface $backend)

Injects the backend to use

Parameters

BackendInterface $backend

the backend to use for persistence

Return Value

void

void injectPersistenceSession(Session $persistenceSession)

Injects the persistence session

Parameters

Session $persistenceSession

The persistence session

Return Value

void

void initializeObject()

Initializes the persistence manager

Return Value

void

Exceptions

MissingBackendException

int getObjectCountByQuery(QueryInterface $query)

Returns the number of records matching the query.

Parameters

QueryInterface $query

Return Value

int

array getObjectDataByQuery(QueryInterface $query)

Returns the object data matching the $query.

Parameters

QueryInterface $query

Return Value

array

void persistAll(bool $onlyAllowedObjects = false)

Commits new objects and changes to objects in the current persistence session into the backend

Parameters

bool $onlyAllowedObjects

Return Value

void

bool isNewObject(object $object)

Checks if the given object has ever been persisted.

Parameters

object $object

The object to check

Return Value

bool

true if the object is new, false if the object exists in the repository

mixed getIdentifierByObject(object $object)

Returns the (internal) identifier for the object, if it is known to the backend. Otherwise NULL is returned.

Note: this returns an identifier even if the object has not been persisted in case of AOP-managed entities. Use isNewObject() if you need to distinguish those cases.

Parameters

object $object

Return Value

mixed

The identifier for the object if it is known, or NULL

object|null getObjectByIdentifier(mixed $identifier, string $objectType = null, bool $useLazyLoading = false)

Returns the object with the (internal) identifier, if it is known to the backend. Otherwise NULL is returned.

Parameters

mixed $identifier
string $objectType
bool $useLazyLoading

Set to true if you want to use lazy loading for this object

Return Value

object|null

The object for the identifier if it is known, or NULL

object getObjectDataByIdentifier(string $identifier, string $objectType = null)

Returns the object data for the (internal) identifier, if it is known to the backend. Otherwise false is returned.

Parameters

string $identifier
string $objectType

Return Value

object

The object data for the identifier if it is known, or false

QueryInterface createQueryForType(string $type)

Return a query object for the given type.

Parameters

string $type

Return Value

QueryInterface

void add(object $object)

Adds an object to the persistence.

Parameters

object $object

The object to add

Return Value

void

void remove(object $object)

Removes an object to the persistence.

Parameters

object $object

The object to remove

Return Value

void

void update(object $object)

Update an object in the persistence.

Parameters

object $object

The modified object

Return Value

void

Exceptions

UnknownObjectException

bool isConnected()

Returns true, if an active connection to the persistence backend has been established, e.g. entities can be persisted.

Return Value

bool

true, if an connection has been established, false if add object will not be persisted by the backend

protected void throwExceptionIfObjectIsNotAllowed(object $object)

Checks if the given object is allowed and if not, throws an exception

Parameters

object $object

Return Value

void

Exceptions

Exception

protected void emitAllObjectsPersisted()

Signals that all persistAll() has been executed successfully.

Return Value

void

void tearDown()

Tear down the persistence

This method is called in functional tests to reset the storage between tests. The implementation is optional and depends on the underlying persistence backend.

Return Value

void