DataMapper

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

Internal

only to be used within Extbase, not part of TYPO3 Core API.

Attributes
#[Autoconfigure]
$public: true
$shared: false

Table of Contents

Properties

$query  : QueryInterface|null

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. This is designed to *not* call class constructor when hydrating, but *do call* initializeObject() if exists and obey eventually registered implementation overrides ("xclass").
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

Methods

__construct()

public __construct(ReflectionService $reflectionService, QueryObjectModelFactory $qomFactory, Session $persistenceSession, DataMapFactory $dataMapFactory, QueryFactoryInterface $queryFactory, EventDispatcherInterface $eventDispatcher, InstantiatorInterface $instantiator, TcaSchemaFactory $tcaSchemaFactory) : mixed
Parameters
$reflectionService : ReflectionService
$qomFactory : QueryObjectModelFactory
$persistenceSession : Session
$dataMapFactory : DataMapFactory
$queryFactory : QueryFactoryInterface
$eventDispatcher : EventDispatcherInterface
$instantiator : InstantiatorInterface
$tcaSchemaFactory : TcaSchemaFactory

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
Tags
phpstan-return

array<non-empty-string, QueryInterface::ORDER_*>|null

Return values
array<string, string>|null

getPlainValue()

Returns a plain value, i.e. objects are flattened out if possible.

public getPlainValue(mixed $input[, ColumnMap|null $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 = 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<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

Tags
phpstan-param

class-string $className

phpstan-return

class-string

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

Tags
template

T of DomainObjectInterface

phpstan-param

class-string<T> $className

phpstan-return

list<T>

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

createEmptyObject()

Creates a skeleton of the specified object. This is designed to *not* call class constructor when hydrating, but *do call* initializeObject() if exists and obey eventually registered implementation overrides ("xclass").

protected createEmptyObject(class-string $className) : DomainObjectInterface
Parameters
$className : class-string

Name of the class to create a skeleton for

Tags
throws
InvalidClassException
template

T of DomainObjectInterface

phpstan-param

class-string<T> $className

phpstan-return

T

Return values
DomainObjectInterface

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

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

Tags
template

T of DomainObjectInterface

phpstan-param

class-string<T> $className

phpstan-return

T

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

        
On this page

Search results