PersistentObjectConverter
class PersistentObjectConverter extends ObjectConverter (View source)
This converter transforms arrays or strings to persistent objects. It does the following:
-
If the input is string, it is assumed to be a UUID. Then, the object is fetched from persistence.
-
If the input is array, we check if it has an identity property.
-
If the input has NO identity property, but additional properties, we create a new object and return it. However, we only do this if the configuration option "CONFIGURATION_CREATION_ALLOWED" is true.
-
If the input has an identity property AND the configuration option "CONFIGURATION_IDENTITY_CREATION_ALLOWED" is set, we fetch the object from persistent or create a new object if none was found and then set the sub-properties.
-
If the input has an identity property and NO additional properties, we fetch the object from persistence.
-
If the input has an identity property AND additional properties, we fetch the object from persistence, and set the sub-properties. We only do this if the configuration option "CONFIGURATION_MODIFICATION_ALLOWED" is true.
Constants
CONFIGURATION_TARGET_TYPE |
|
CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED |
|
PATTERN_MATCH_UUID |
|
CONFIGURATION_MODIFICATION_ALLOWED |
|
CONFIGURATION_CREATION_ALLOWED |
|
CONFIGURATION_IDENTITY_CREATION_ALLOWED |
|
Properties
protected array | $sourceTypes | ||
protected string | $targetType | from ObjectConverter | |
protected int | $priority | ||
protected ObjectManagerInterface | $objectManager | from ObjectConverter | |
protected ReflectionService | $reflectionService | from ObjectConverter | |
protected array | $constructorReflectionFirstLevelCache | As it is very likely that the constructor arguments are needed twice we should cache them for the request. |
from ObjectConverter |
protected PersistenceManagerInterface | $persistenceManager |
Methods
Returns the list of source types the TypeConverter can handle.
Return the target type this TypeConverter converts to.
Determines the target type based on the source's (optional) __type key.
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
We can only convert if the $targetType is either tagged with entity or value object.
All properties in the source array except __identity are sub-properties.
The type of a property is determined by the reflection service.
Convert an object from $source to an entity or a value object.
Builds a new instance of $objectType with the given $possibleConstructorArgumentValues.
Get the constructor argument reflection for the given object type.
Handle the case if $source is an array.
Set the given $identity on the created $object.
Fetch an object from persistence layer.
Finds an object from the repository by searching for its identity properties.
Details
string[]
getSupportedSourceTypes()
Returns the list of source types the TypeConverter can handle.
Must be PHP simple types, classes or object is not allowed.
string
getSupportedTargetType()
Return the target type this TypeConverter converts to.
Can be a simple type or a class name.
string
getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)
Determines the target type based on the source's (optional) __type key.
int
getPriority()
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
bool
canConvertFrom(mixed $source, string $targetType)
We can only convert if the $targetType is either tagged with entity or value object.
array
getSourceChildPropertiesToBeConverted(mixed $source)
All properties in the source array except __identity are sub-properties.
string
getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)
The type of a property is determined by the reflection service.
mixed|null|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
Convert an object from $source to an entity or a value object.
protected object
buildObject(array $possibleConstructorArgumentValues, string $objectType)
Builds a new instance of $objectType with the given $possibleConstructorArgumentValues.
If constructor argument values are missing from the given array the method looks for a default value in the constructor signature.
Furthermore, the constructor arguments are removed from $possibleConstructorArgumentValues
protected array[]
getConstructorArgumentsForClass(string $className)
Get the constructor argument reflection for the given object type.
protected object|TargetNotFoundError
handleArrayData(array $source, string $targetType, array $convertedChildProperties, PropertyMappingConfigurationInterface $configuration = null)
Handle the case if $source is an array.
protected void
setIdentity(object $object, string|array $identity)
Set the given $identity on the created $object.
protected object|null
fetchObjectFromPersistence(mixed $identity, string $targetType)
Fetch an object from persistence layer.
protected object|null
findObjectByIdentityProperties(array $identityProperties, string $type)
Finds an object from the repository by searching for its identity properties.