DataMapper
A mapper to map database tables configured in $TCA on domain objects.
only to be used within Extbase, not part of TYPO3 Core API.
Table of Contents
Properties
- $dataMapFactory : DataMapFactory
- $eventDispatcher : EventDispatcherInterface
- $objectManager : ObjectManagerInterface
- $persistenceSession : Session
- $qomFactory : QueryObjectModelFactory
- $query : QueryInterface|null
- $queryFactory : QueryFactoryInterface
- $reflectionService : ReflectionService
Methods
- __construct() : mixed
- convertClassNameToTableName() : string
- Returns the selector (table) name for a given class name.
- convertPropertyNameToColumnName() : string
- Returns the column name for a given property name of the specified class.
- countRelated() : int
- Counts the number of related objects assigned to a property of a parent object
- fetchRelated() : LazyObjectStorage|QueryResultInterface
- Fetches a collection of objects related to a property of a parent object
- getDataMap() : DataMap
- Returns a data map for a given class name
- getOrderingsForColumnMap() : array<string, string>|null
- Get orderings array for extbase query by columnMap
- getPlainValue() : int|string
- Returns a plain value, i.e. objects are flattened out if possible.
- getTargetType() : string
- Returns the target type for the given row.
- getType() : string
- Returns the type of a child object.
- map() : array<string|int, mixed>
- Maps the given rows on objects
- mapResultToPropertyValue() : mixed
- Returns the given result as property value of the specified property type.
- setQuery() : void
- createEmptyObject() : DomainObjectInterface
- Creates a skeleton of the specified object
- fetchRelatedEager() : mixed
- Fetches the related objects from the storage backend.
- getConstraint() : ConstraintInterface
- Builds and returns the constraint for multi value properties.
- getEmptyRelationValue() : array<string|int, mixed>|null
- getNonEmptyRelationValue() : QueryResultInterface
- getPreparedQuery() : QueryInterface
- Builds and returns the prepared query, ready to be executed.
- getSource() : SourceInterface
- Builds and returns the source to build a join for a m:n relation.
- mapCoreType() : TypeInterface
- Map value to a core type
- mapDateTime() : DateTimeInterface
- Creates a DateTime from a unix timestamp or date/datetime/time value.
- mapObjectToClassProperty() : mixed
- Returns the mapped classProperty from the identityMap or mapResultToPropertyValue()
- mapSingleRow() : object
- Maps a single row on an object of the given class
- propertyMapsByForeignKey() : bool
- Checks if the relation is based on a foreign key.
- resolveRelationValuesOfField() : array<string|int, mixed>|false|mixed
- This resolves relations via RelationHandler and returns their UIDs respectively, and works for MM/ForeignField/CSV in IRRE + Select + Group.
- thawProperties() : mixed
- Sets the given properties on the object.
Properties
$dataMapFactory
protected
DataMapFactory
$dataMapFactory
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$objectManager
protected
ObjectManagerInterface
$objectManager
$persistenceSession
protected
Session
$persistenceSession
$qomFactory
protected
QueryObjectModelFactory
$qomFactory
$query
protected
QueryInterface|null
$query
$queryFactory
protected
QueryFactoryInterface
$queryFactory
$reflectionService
protected
ReflectionService
$reflectionService
Methods
__construct()
public
__construct(ReflectionService $reflectionService, QueryObjectModelFactory $qomFactory, Session $persistenceSession, DataMapFactory $dataMapFactory, QueryFactoryInterface $queryFactory, ObjectManagerInterface $objectManager, EventDispatcherInterface $eventDispatcher) : mixed
Parameters
- $reflectionService : ReflectionService
- $qomFactory : QueryObjectModelFactory
- $persistenceSession : Session
- $dataMapFactory : DataMapFactory
- $queryFactory : QueryFactoryInterface
- $objectManager : ObjectManagerInterface
- $eventDispatcher : EventDispatcherInterface
convertClassNameToTableName()
Returns the selector (table) name for a given class name.
public
convertClassNameToTableName(string $className) : string
Parameters
- $className : string
Return values
string —The selector name
convertPropertyNameToColumnName()
Returns the column name for a given property name of the specified class.
public
convertPropertyNameToColumnName(string $propertyName[, string $className = null ]) : string
Parameters
- $propertyName : string
- $className : string = null
Return values
string —The column name
countRelated()
Counts the number of related objects assigned to a property of a parent object
public
countRelated(DomainObjectInterface $parentObject, string $propertyName[, mixed $fieldValue = '' ]) : int
Parameters
- $parentObject : DomainObjectInterface
-
The object instance this proxy is part of
- $propertyName : string
-
The name of the proxied property in it's parent
- $fieldValue : mixed = ''
-
The raw field value.
Return values
intfetchRelated()
Fetches a collection of objects related to a property of a parent object
public
fetchRelated(DomainObjectInterface $parentObject, string $propertyName[, mixed $fieldValue = '' ][, bool $enableLazyLoading = true ]) : LazyObjectStorage|QueryResultInterface
Parameters
- $parentObject : DomainObjectInterface
-
The object instance this proxy is part of
- $propertyName : string
-
The name of the proxied property in it's parent
- $fieldValue : mixed = ''
-
The raw field value.
- $enableLazyLoading : bool = true
-
A flag indication if the related objects should be lazy loaded
Return values
LazyObjectStorage|QueryResultInterface —The result
getDataMap()
Returns a data map for a given class name
public
getDataMap(string $className) : DataMap
Parameters
- $className : string
-
The class name you want to fetch the Data Map for
Tags
Return values
DataMap —The data map
getOrderingsForColumnMap()
Get orderings array for extbase query by columnMap
public
getOrderingsForColumnMap(ColumnMap $columnMap) : array<string, string>|null
Parameters
- $columnMap : ColumnMap
Return values
array<string, string>|nullgetPlainValue()
Returns a plain value, i.e. objects are flattened out if possible.
public
getPlainValue(mixed $input[, ColumnMap $columnMap = null ]) : int|string
Multi value objects or arrays will be converted to a comma-separated list for use in IN SQL queries.
Parameters
- $input : mixed
-
The value that will be converted.
- $columnMap : ColumnMap = null
-
Optional column map for retrieving the date storage format.
Tags
Return values
int|stringgetTargetType()
Returns the target type for the given row.
public
getTargetType(string $className, array<string|int, mixed> $row) : string
Parameters
- $className : string
-
The name of the class
- $row : array<string|int, mixed>
-
A single array with field_name => value pairs
Return values
string —The target type (a class name)
getType()
Returns the type of a child object.
public
getType(string $parentClassName, string $propertyName) : string
Parameters
- $parentClassName : string
-
The class name of the object this proxy is part of
- $propertyName : string
-
The name of the proxied property in it's parent
Tags
Return values
string —The class name of the child object
map()
Maps the given rows on objects
public
map(string $className, array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
- $className : string
-
The name of the class
- $rows : array<string|int, mixed>
-
An array of arrays with field_name => value pairs
Return values
array<string|int, mixed> —An array of objects of the given class
mapResultToPropertyValue()
Returns the given result as property value of the specified property type.
public
mapResultToPropertyValue(DomainObjectInterface $parentObject, string $propertyName, mixed $result) : mixed
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
- $result : mixed
-
The result
setQuery()
public
setQuery(QueryInterface $query) : void
Parameters
- $query : QueryInterface
createEmptyObject()
Creates a skeleton of the specified object
protected
createEmptyObject(string $className) : DomainObjectInterface
Parameters
- $className : string
-
Name of the class to create a skeleton for
Tags
Return values
DomainObjectInterface —The object skeleton
fetchRelatedEager()
Fetches the related objects from the storage backend.
protected
fetchRelatedEager(DomainObjectInterface $parentObject, string $propertyName[, mixed $fieldValue = '' ]) : mixed
Parameters
- $parentObject : DomainObjectInterface
-
The object instance this proxy is part of
- $propertyName : string
-
The name of the proxied property in it's parent
- $fieldValue : mixed = ''
-
The raw field value.
getConstraint()
Builds and returns the constraint for multi value properties.
protected
getConstraint(QueryInterface $query, DomainObjectInterface $parentObject, string $propertyName[, string $fieldValue = '' ][, array<string|int, mixed> $relationTableMatchFields = [] ]) : ConstraintInterface
Parameters
- $query : QueryInterface
- $parentObject : DomainObjectInterface
- $propertyName : string
- $fieldValue : string = ''
- $relationTableMatchFields : array<string|int, mixed> = []
Return values
ConstraintInterface —$constraint
getEmptyRelationValue()
protected
getEmptyRelationValue(DomainObjectInterface $parentObject, string $propertyName) : array<string|int, mixed>|null
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
Return values
array<string|int, mixed>|nullgetNonEmptyRelationValue()
protected
getNonEmptyRelationValue(DomainObjectInterface $parentObject, string $propertyName, string $fieldValue) : QueryResultInterface
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
- $fieldValue : string
Return values
QueryResultInterfacegetPreparedQuery()
Builds and returns the prepared query, ready to be executed.
protected
getPreparedQuery(DomainObjectInterface $parentObject, string $propertyName[, string $fieldValue = '' ]) : QueryInterface
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
- $fieldValue : string = ''
Return values
QueryInterfacegetSource()
Builds and returns the source to build a join for a m:n relation.
protected
getSource(DomainObjectInterface $parentObject, string $propertyName) : SourceInterface
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
Return values
SourceInterface —$source
mapCoreType()
Map value to a core type
protected
mapCoreType(string $type, mixed $value) : TypeInterface
Parameters
- $type : string
- $value : mixed
Return values
TypeInterfacemapDateTime()
Creates a DateTime from a unix timestamp or date/datetime/time value.
protected
mapDateTime(int|string $value[, string|null $storageFormat = null ][, string $targetType = DateTime::class ]) : DateTimeInterface
If the input is empty, NULL is returned.
Parameters
- $value : int|string
-
Unix timestamp or date/datetime/time value
- $storageFormat : string|null = null
-
Storage format for native date/datetime/time fields
- $targetType : string = DateTime::class
-
The object class name to be created
Return values
DateTimeInterfacemapObjectToClassProperty()
Returns the mapped classProperty from the identityMap or mapResultToPropertyValue()
protected
mapObjectToClassProperty(DomainObjectInterface $parentObject, string $propertyName, mixed $fieldValue) : mixed
If the field value is empty and the column map has no parent key field name, the relation will be empty. If the persistence session has a registered object of the correct type and identity (fieldValue), this function returns that object. Otherwise, it proceeds with mapResultToPropertyValue().
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
- $fieldValue : mixed
-
the raw field value
Tags
mapSingleRow()
Maps a single row on an object of the given class
protected
mapSingleRow(string $className, array<string|int, mixed> $row) : object
Parameters
- $className : string
-
The name of the target class
- $row : array<string|int, mixed>
-
A single array with field_name => value pairs
Return values
object —An object of the given class
propertyMapsByForeignKey()
Checks if the relation is based on a foreign key.
protected
propertyMapsByForeignKey(DomainObjectInterface $parentObject, string $propertyName) : bool
Parameters
- $parentObject : DomainObjectInterface
- $propertyName : string
Return values
bool —TRUE if the property is mapped
resolveRelationValuesOfField()
This resolves relations via RelationHandler and returns their UIDs respectively, and works for MM/ForeignField/CSV in IRRE + Select + Group.
protected
resolveRelationValuesOfField(DataMap $dataMap, ColumnMap $columnMap, DomainObjectInterface $parentObject, string $fieldValue, int $workspaceId) : array<string|int, mixed>|false|mixed
Note: This only happens for resolving properties for models. When limiting a parentQuery, the Typo3DbQueryParser is taking care of it.
By using the RelationHandler, the localized, deleted and moved records turn out to be properly resolved without having to build intermediate queries.
This is currently only used in workspaces' context, as it is 1 additional DB query needed.
Parameters
- $dataMap : DataMap
- $columnMap : ColumnMap
- $parentObject : DomainObjectInterface
- $fieldValue : string
- $workspaceId : int
Return values
array<string|int, mixed>|false|mixedthawProperties()
Sets the given properties on the object.
protected
thawProperties(DomainObjectInterface $object, array<string|int, mixed> $row) : mixed
Parameters
- $object : DomainObjectInterface
-
The object to set properties on
- $row : array<string|int, mixed>