PersistentObjectConverter

class \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter

Extends
ObjectConverter

This converter transforms arrays or strings to persistent objects. It does the following:

  • If the input is string, it is assumed to be a UID. Then, the object is fetched from persistence.

  • If the input is array, we check if it has an identity property.

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

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

Table of Contents

Constants

CONFIGURATION_CREATION_ALLOWED  : int = 2
CONFIGURATION_MODIFICATION_ALLOWED  : int = 1
CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED  : int = 4
CONFIGURATION_TARGET_TYPE  : int = 3

Properties

$container  : ContainerInterface
$persistenceManager  : PersistenceManagerInterface
$priority  : int
The priority for this converter.
$reflectionService  : ReflectionService
$sourceTypes  : array
The source types this converter can convert.
$targetType  : string
The target type this converter can convert to.

Methods

canConvertFrom()  : bool
We can only convert if the $targetType is either tagged with entity or value object.
convertFrom()  : object|null
Convert an object from $source to an entity or a value object.
getPriority()  : int
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
getSourceChildPropertiesToBeConverted()  : array
All properties in the source array except __identity are sub-properties.
getSupportedSourceTypes()  : string[]
Returns the list of source types the TypeConverter can handle.
getSupportedTargetType()  : string
Return the target type this TypeConverter converts to.
getTargetTypeForSource()  : string
Determines the target type based on the source's (optional) __type key and by evaluating possible XCLASS overrides of the target type.
getTypeOfChildProperty()  : string
The type of a property is determined by the reflection service.
injectContainer()  : mixed
injectPersistenceManager()  : void
injectReflectionService()  : void
buildObject()  : object
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: They are considered "handled" by __construct and will not be mapped calling setters later.
fetchObjectFromPersistence()  : object
Fetch an object from persistence layer.
handleArrayData()  : object
Handle the case if $source is an array.

Constants

CONFIGURATION_CREATION_ALLOWED

public int CONFIGURATION_CREATION_ALLOWED = 2

CONFIGURATION_MODIFICATION_ALLOWED

public int CONFIGURATION_MODIFICATION_ALLOWED = 1

CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED

public int CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED = 4

CONFIGURATION_TARGET_TYPE

public int CONFIGURATION_TARGET_TYPE = 3

Properties

$container

protected ContainerInterface $container

$priority

The priority for this converter.

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

protected int $priority = 20

$sourceTypes

The source types this converter can convert.

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

protected array $sourceTypes = ['integer', 'string', 'array']

$targetType

The target type this converter can convert to.

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

protected string $targetType = 'object'

Methods

canConvertFrom()

We can only convert if the $targetType is either tagged with entity or value object.

public canConvertFrom(mixed $source, string $targetType) : bool

Parameters

$source : mixed
$targetType : string

Return values

bool

convertFrom()

Convert an object from $source to an entity or a value object.

public convertFrom(mixed $source, string $targetType[, array $convertedChildProperties = [] ][, PropertyMappingConfigurationInterface|null $configuration = null ]) : object|null

Parameters

$source : mixed
$targetType : string
$convertedChildProperties : array = []
$configuration : PropertyMappingConfigurationInterface|null = null

Tags

throws
InvalidArgumentException
throws
InvalidTargetException

Return values

object|null —

the target type

getPriority()

Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.

public getPriority() : int

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

Return values

int

getSourceChildPropertiesToBeConverted()

All properties in the source array except __identity are sub-properties.

public getSourceChildPropertiesToBeConverted(mixed $source) : array

Parameters

$source : mixed

Return values

array

getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

public getSupportedSourceTypes() : string[]

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

Must be PHP simple types, classes or object is not allowed.

Return values

string[]

getSupportedTargetType()

Return the target type this TypeConverter converts to.

public getSupportedTargetType() : string

Deprecated

will be removed in TYPO3 v13.0, as this is defined in Services.yaml.

Can be a simple type or a class name.

Return values

string

getTargetTypeForSource()

Determines the target type based on the source's (optional) __type key and by evaluating possible XCLASS overrides of the target type.

public getTargetTypeForSource(mixed $source, string $originalTargetType[, PropertyMappingConfigurationInterface|null $configuration = null ]) : string

Parameters

$source : mixed
$originalTargetType : string

the type we originally want to convert to

$configuration : PropertyMappingConfigurationInterface|null = null

Tags

throws
InvalidDataTypeException
throws
InvalidPropertyMappingConfigurationException
throws
InvalidArgumentException

Return values

string

getTypeOfChildProperty()

The type of a property is determined by the reflection service.

public getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration) : string

Parameters

$targetType : string
$propertyName : string
$configuration : PropertyMappingConfigurationInterface

Tags

throws
InvalidTargetException

Return values

string —

the type of $propertyName in $targetType

injectContainer()

public injectContainer(ContainerInterface $container) : mixed

Parameters

$container : ContainerInterface

buildObject()

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: They are considered "handled" by __construct and will not be mapped calling setters later.

protected buildObject(array &$possibleConstructorArgumentValues, string $objectType) : object

Parameters

$possibleConstructorArgumentValues : array
$objectType : string

Tags

throws
InvalidTargetException

if a required constructor argument is missing

Return values

object —

The created instance

fetchObjectFromPersistence()

Fetch an object from persistence layer.

protected fetchObjectFromPersistence(mixed $identity, string $targetType) : object

Parameters

$identity : mixed
$targetType : string

Tags

throws
TargetNotFoundException
throws
InvalidSourceException

Return values

object
On this page