abstract class AbstractBackend implements BackendInterface (View source)

deprecated since Flow 6.0

An abstract storage backend for the Flow persistence

Constants

OBJECTSTATE_RECONSTITUTED

An object that was reconstituted

OBJECTSTATE_NEW

An object that is new

Properties

protected ReflectionService $reflectionService
protected Session $persistenceSession
protected PersistenceManagerInterface $persistenceManager
protected ValidatorResolver $validatorResolver
protected LoggerInterface $logger
protected SplObjectStorage $visitedDuringPersistence
protected SplObjectStorage $aggregateRootObjects
protected SplObjectStorage $deletedEntities
protected SplObjectStorage $changedEntities
protected array $classSchemata

Methods

__construct()

Constructs the backend

void
injectReflectionService(ReflectionService $reflectionService)

Injects a Reflection Service instance used for processing objects

void
injectPersistenceSession(Session $persistenceSession)

Injects the persistence session

void
setPersistenceManager(PersistenceManagerInterface $persistenceManager)

Set a PersistenceManager instance.

void
injectValidatorResolver(ValidatorResolver $validatorResolver)

Injects the ValidatorResolver

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

void
emitRemovedObject(object $object)

Signalizes that the given object has been removed

void
emitPersistedObject(object $object, int $objectState)

Signalizes that the given object has been persisted

void
initialize(array $options)

Initializes the backend

void
setAggregateRootObjects(SplObjectStorage $objects)

Sets the aggregate root objects

void
setChangedEntities(SplObjectStorage $entities)

Sets the changed objects

void
setDeletedEntities(SplObjectStorage $entities)

Sets the deleted objects

void
commit()

Commits the current persistence session.

bool
isConnected()

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

void
persistObjects()

First persist new objects, then check reconstituted entities.

string
persistObject(object $object, string $parentIdentifier)

Stores or updates an object in the underlying storage.

int
storeObject(object $object, string $identifier, string $parentIdentifier, array $objectData)

Actually store an object, backend-specific

void
processDeletedObjects()

Iterate over deleted entities and process them

void
removeEntity(object $object)

Remove an entity

void
removeValueObject(object $object)

Remove a value object

void
validateObject(object $object)

Validates the given object and throws an exception if validation fails.

string
getType(mixed $value)

Returns the type of $value, i.e. the class name or primitive type.

string
getTypeName(string $type)

Returns the type name as used in the database table names.

array
collectProperties(string $identifier, object $object, array $properties, bool $dirty)

No description

void
flattenValue(string $identifier, object $object, string $propertyName, array $propertyMetaData, array $propertyData)

Convert a value to the internal object data format

void
removeDeletedReference(object $object, string $propertyName, array $propertyMetaData)

Remove any unreferenced non aggregate root entity

array
processObject(object $object, string $parentIdentifier)

No description

mixed
checkPropertyValue(object $object, string $propertyName, array $propertyMetaData)

Check the property value for allowed types and throw exceptions for unsupported types.

array
processArray(array $array = null, string $parentIdentifier, array $previousArray = null)

Store an array as a set of records, with each array element becoming a property named like the key and the value.

string
processNestedArray(string $parentIdentifier, array $nestedArray, Closure $handler = null)

"Serializes" a nested array for storage.

void
removeDeletedArrayEntries(array $array = null, array $previousArray)

Remove objects removed from array compared to $previousArray.

bool
arrayContainsObject(array $array, object $object, string $identifier)

Checks whether the given object is contained in the array. This checks for object identity in terms of the persistence layer, i.e. the UUID, when comparing entities.

array
processSplObjectStorage(SplObjectStorage $splObjectStorage = null, string $parentIdentifier, array $previousObjectStorage = null)

Store an SplObjectStorage as a set of records.

void
removeDeletedSplObjectStorageEntries(SplObjectStorage $splObjectStorage = null, array $previousObjectStorage)

Remove objects removed from SplObjectStorage compared to $previousSplObjectStorage.

int
processDateTime(DateTimeInterface $dateTime = null)

Creates a unix timestamp from the given DateTime object. If NULL is given NULL will be returned.

Details

__construct()

Constructs the backend

void injectReflectionService(ReflectionService $reflectionService)

Injects a Reflection Service instance used for processing objects

Parameters

ReflectionService $reflectionService

Return Value

void

void injectPersistenceSession(Session $persistenceSession)

Injects the persistence session

Parameters

Session $persistenceSession

Return Value

void

void setPersistenceManager(PersistenceManagerInterface $persistenceManager)

Set a PersistenceManager instance.

Parameters

PersistenceManagerInterface $persistenceManager

Return Value

void

void injectValidatorResolver(ValidatorResolver $validatorResolver)

Injects the ValidatorResolver

Parameters

ValidatorResolver $validatorResolver

Return Value

void

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

protected void emitRemovedObject(object $object)

Signalizes that the given object has been removed

Parameters

object $object

The object that will be removed

Return Value

void

protected void emitPersistedObject(object $object, int $objectState)

Signalizes that the given object has been persisted

Parameters

object $object

The object that will be persisted

int $objectState

The state, see self::OBJECTSTATE_*

Return Value

void

void initialize(array $options)

Initializes the backend

Parameters

array $options

Return Value

void

void setAggregateRootObjects(SplObjectStorage $objects)

Sets the aggregate root objects

Parameters

SplObjectStorage $objects

Return Value

void

void setChangedEntities(SplObjectStorage $entities)

Sets the changed objects

Parameters

SplObjectStorage $entities

Return Value

void

void setDeletedEntities(SplObjectStorage $entities)

Sets the deleted objects

Parameters

SplObjectStorage $entities

Return Value

void

void commit()

Commits the current persistence session.

Return Value

void

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 persistObjects()

First persist new objects, then check reconstituted entities.

Return Value

void

protected string persistObject(object $object, string $parentIdentifier)

Stores or updates an object in the underlying storage.

Parameters

object $object

The object to persist

string $parentIdentifier

Return Value

string

abstract protected int storeObject(object $object, string $identifier, string $parentIdentifier, array $objectData)

Actually store an object, backend-specific

Parameters

object $object
string $identifier
string $parentIdentifier
array $objectData

Return Value

int

one of self::OBJECTSTATE_*

protected void processDeletedObjects()

Iterate over deleted entities and process them

Return Value

void

abstract protected void removeEntity(object $object)

Remove an entity

Parameters

object $object

Return Value

void

abstract protected void removeValueObject(object $object)

Remove a value object

Parameters

object $object

Return Value

void

protected void validateObject(object $object)

Validates the given object and throws an exception if validation fails.

Parameters

object $object

Return Value

void

Exceptions

ObjectValidationFailedException

protected string getType(mixed $value)

Returns the type of $value, i.e. the class name or primitive type.

Parameters

mixed $value

Return Value

string

protected string getTypeName(string $type)

Returns the type name as used in the database table names.

Parameters

string $type

Return Value

string

protected array collectProperties(string $identifier, object $object, array $properties, bool $dirty)

No description

Parameters

string $identifier

The object's identifier

object $object

The object to work on

array $properties

The properties to collect (as per class schema)

bool $dirty

A dirty flag that is passed by reference and set to true if a dirty property was found

Return Value

array

protected void flattenValue(string $identifier, object $object, string $propertyName, array $propertyMetaData, array $propertyData)

Convert a value to the internal object data format

Parameters

string $identifier

The object's identifier

object $object

The object with the property to flatten

string $propertyName

The name of the property

array $propertyMetaData

The property metadata

array $propertyData

Reference to the property data array

Return Value

void

protected void removeDeletedReference(object $object, string $propertyName, array $propertyMetaData)

Remove any unreferenced non aggregate root entity

Parameters

object $object
string $propertyName
array $propertyMetaData

Return Value

void

protected array processObject(object $object, string $parentIdentifier)

No description

Parameters

object $object
string $parentIdentifier

Return Value

array

protected mixed checkPropertyValue(object $object, string $propertyName, array $propertyMetaData)

Check the property value for allowed types and throw exceptions for unsupported types.

Parameters

object $object

The object with the property to check

string $propertyName

The name of the property to check

array $propertyMetaData

Property metadata

Return Value

mixed

The value of the property

Exceptions

UnexpectedTypeException
Exception
IllegalObjectTypeException

protected array processArray(array $array = null, string $parentIdentifier, array $previousArray = null)

Store an array as a set of records, with each array element becoming a property named like the key and the value.

Note: Objects contained in the array will have a matching entry created, the objects must be persisted elsewhere!

Parameters

array $array

The array to persist

string $parentIdentifier
array $previousArray

the previously persisted state of the array

Return Value

array

An array with "flat" values representing the array

Exceptions

Exception

protected string processNestedArray(string $parentIdentifier, array $nestedArray, Closure $handler = null)

"Serializes" a nested array for storage.

Parameters

string $parentIdentifier
array $nestedArray
Closure $handler

Return Value

string

protected void removeDeletedArrayEntries(array $array = null, array $previousArray)

Remove objects removed from array compared to $previousArray.

Parameters

array $array
array $previousArray

Return Value

void

protected bool arrayContainsObject(array $array, object $object, string $identifier)

Checks whether the given object is contained in the array. This checks for object identity in terms of the persistence layer, i.e. the UUID, when comparing entities.

Parameters

array $array
object $object
string $identifier

Return Value

bool

protected array processSplObjectStorage(SplObjectStorage $splObjectStorage = null, string $parentIdentifier, array $previousObjectStorage = null)

Store an SplObjectStorage as a set of records.

Note: Objects contained in the SplObjectStorage will have a matching entry created, the objects must be persisted elsewhere!

Parameters

SplObjectStorage $splObjectStorage

The SplObjectStorage to persist

string $parentIdentifier
array $previousObjectStorage

the previously persisted state of the SplObjectStorage

Return Value

array

An array with "flat" values representing the SplObjectStorage

Exceptions

Exception

protected void removeDeletedSplObjectStorageEntries(SplObjectStorage $splObjectStorage = null, array $previousObjectStorage)

Remove objects removed from SplObjectStorage compared to $previousSplObjectStorage.

Parameters

SplObjectStorage $splObjectStorage
array $previousObjectStorage

Return Value

void

protected int processDateTime(DateTimeInterface $dateTime = null)

Creates a unix timestamp from the given DateTime object. If NULL is given NULL will be returned.

Parameters

DateTimeInterface $dateTime

Return Value

int