DataMapper

class \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper

A mapper to map database tables configured in $TCA on domain objects.

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

$eventDispatcher

protected EventDispatcherInterface $eventDispatcher

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

int

fetchRelated()

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

throws
Exception

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>|null

getPlainValue()

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

throws
InvalidArgumentException
throws
UnexpectedTypeException

Return values

int|string

getTargetType()

Returns the target type for the given row.

public getTargetType(string $className, array $row) : string

Parameters

$className : string

The name of the class

$row : array

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

throws
UnexpectedTypeException

Return values

string —

The class name of the child object

map()

Maps the given rows on objects

public map(string $className, array $rows) : array

Parameters

$className : string

The name of the class

$rows : array

An array of arrays with field_name => value pairs

Return values

array —

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

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 $relationTableMatchFields = [] ]) : ConstraintInterface

Parameters

$query : QueryInterface
$parentObject : DomainObjectInterface
$propertyName : string
$fieldValue : string = ''
$relationTableMatchFields : array = []

Return values

ConstraintInterface —

$constraint

mapCoreType()

Map value to a core type

protected mapCoreType(string $type, mixed $value) : TypeInterface

Parameters

$type : string
$value : mixed

Return values

TypeInterface

mapDateTime()

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

DateTimeInterface

mapObjectToClassProperty()

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

see
mapResultToPropertyValue()

mapSingleRow()

Maps a single row on an object of the given class

protected mapSingleRow(string $className, array $row) : object

Parameters

$className : string

The name of the target class

$row : array

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|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|false|mixed
On this page