TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DataMapper Class Reference
Inheritance diagram for DataMapper:
SingletonInterface

Public Member Functions

 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 injectQomFactory (\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
 
 injectPersistenceSession (\TYPO3\CMS\Extbase\Persistence\Generic\Session $persistenceSession)
 
 injectDataMapFactory (\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory)
 
 injectQueryFactory (\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface $queryFactory)
 
 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectSignalSlotDispatcher (\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
 
 map ($className, array $rows)
 
 getTargetType ($className, array $row)
 
 fetchRelated (DomainObjectInterface $parentObject, $propertyName, $fieldValue= '', $enableLazyLoading=true)
 
 mapResultToPropertyValue (DomainObjectInterface $parentObject, $propertyName, $result)
 
 countRelated (DomainObjectInterface $parentObject, $propertyName, $fieldValue= '')
 
 isPersistableProperty ($className, $propertyName)
 
 getDataMap ($className)
 
 convertClassNameToTableName ($className)
 
 convertPropertyNameToColumnName ($propertyName, $className=null)
 
 getType ($parentClassName, $propertyName)
 
 getPlainValue ($input, $columnMap=null, $parseStringValueCallback=null, array $parseStringValueCallbackParameters=[])
 

Protected Member Functions

 mapSingleRow ($className, array $row)
 
 emitAfterMappingSingleRow (DomainObjectInterface $object)
 
 createEmptyObject ($className)
 
 thawProperties (DomainObjectInterface $object, array $row)
 
 mapCoreType ($type, $value)
 
 mapDateTime ($value, $storageFormat=null, $targetType= 'DateTime')
 
 fetchRelatedEager (DomainObjectInterface $parentObject, $propertyName, $fieldValue= '')
 
 getEmptyRelationValue (DomainObjectInterface $parentObject, $propertyName)
 
 getNonEmptyRelationValue (DomainObjectInterface $parentObject, $propertyName, $fieldValue)
 
 getPreparedQuery (DomainObjectInterface $parentObject, $propertyName, $fieldValue= '')
 
 getConstraint (Persistence\QueryInterface $query, DomainObjectInterface $parentObject, $propertyName, $fieldValue= '', $relationTableMatchFields=[])
 
 getSource (DomainObjectInterface $parentObject, $propertyName)
 
 mapObjectToClassProperty (DomainObjectInterface $parentObject, $propertyName, $fieldValue)
 
 propertyMapsByForeignKey (DomainObjectInterface $parentObject, $propertyName)
 
 getPlainStringValue ($value, $callback=null, array $additionalParameters=[])
 

Protected Attributes

 $reflectionService
 
 $qomFactory
 
 $persistenceSession
 
 $pageSelectObject
 
 $dataMaps = []
 
 $dataMapFactory
 
 $queryFactory
 
 $objectManager
 
 $signalSlotDispatcher
 

Detailed Description

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

Definition at line 26 of file DataMapper.php.

Member Function Documentation

convertClassNameToTableName (   $className)

Returns the selector (table) name for a given class name.

Parameters
string$className
Returns
string The selector name

Definition at line 629 of file DataMapper.php.

References DataMapper\getDataMap().

convertPropertyNameToColumnName (   $propertyName,
  $className = null 
)

Returns the column name for a given property name of the specified class.

Parameters
string$propertyName
string$className
Returns
string The column name

Definition at line 641 of file DataMapper.php.

References DataMapper\getDataMap().

countRelated ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue = '' 
)

Counts the number of related objects assigned to a property of a parent object

Parameters
DomainObjectInterface$parentObjectThe object instance this proxy is part of
string$propertyNameThe name of the proxied property in it's parent
mixed$fieldValueThe raw field value.
Returns
int

Definition at line 585 of file DataMapper.php.

References DataMapper\getPreparedQuery().

createEmptyObject (   $className)
protected

Creates a skeleton of the specified object

Parameters
string$classNameName of the class to create a skeleton for
Exceptions
CannotReconstituteObjectException
Returns
object The object skeleton

Definition at line 211 of file DataMapper.php.

Referenced by DataMapper\mapSingleRow().

emitAfterMappingSingleRow ( DomainObjectInterface  $object)
protected

Emits a signal after mapping a single row.

Parameters
DomainObjectInterface$objectThe mapped object

Definition at line 199 of file DataMapper.php.

Referenced by DataMapper\mapSingleRow().

fetchRelated ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue = '',
  $enableLazyLoading = true 
)

Fetches a collection of objects related to a property of a parent object

Parameters
DomainObjectInterface$parentObjectThe object instance this proxy is part of
string$propertyNameThe name of the proxied property in it's parent
mixed$fieldValueThe raw field value.
bool$enableLazyLoadingA flag indication if the related objects should be lazy loaded
Returns
|Persistence The result

Definition at line 350 of file DataMapper.php.

References DataMapper\fetchRelatedEager().

Referenced by DataMapper\mapObjectToClassProperty(), and DataMapper\thawProperties().

fetchRelatedEager ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue = '' 
)
protected

Fetches the related objects from the storage backend.

Parameters
DomainObjectInterface$parentObjectThe object instance this proxy is part of
string$propertyNameThe name of the proxied property in it's parent
mixed$fieldValueThe raw field value.
Returns
mixed

Definition at line 377 of file DataMapper.php.

References DataMapper\getEmptyRelationValue(), and DataMapper\getNonEmptyRelationValue().

Referenced by DataMapper\fetchRelated().

getConstraint ( Persistence\QueryInterface  $query,
DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue = '',
  $relationTableMatchFields = [] 
)
protected

Builds and returns the constraint for multi value properties.

Parameters
Persistence\QueryInterface$query
DomainObjectInterface$parentObject
string$propertyName
string$fieldValue
array$relationTableMatchFields
Returns
$constraint

Definition at line 445 of file DataMapper.php.

References DataMapper\getDataMap(), and GeneralUtility\intExplode().

Referenced by DataMapper\getPreparedQuery().

getDataMap (   $className)
getEmptyRelationValue ( DomainObjectInterface  $parentObject,
  $propertyName 
)
protected
Parameters
DomainObjectInterface$parentObject
string$propertyName
Returns
array|NULL

Definition at line 387 of file DataMapper.php.

References DataMapper\getDataMap(), and ColumnMap\RELATION_HAS_ONE.

Referenced by DataMapper\fetchRelatedEager(), and DataMapper\mapObjectToClassProperty().

getNonEmptyRelationValue ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue 
)
protected
Parameters
DomainObjectInterface$parentObject
string$propertyName
string$fieldValue
Returns
Persistence

Definition at line 400 of file DataMapper.php.

References DataMapper\getPreparedQuery().

Referenced by DataMapper\fetchRelatedEager().

getPlainStringValue (   $value,
  $callback = null,
array  $additionalParameters = [] 
)
protected

If the given callback is set the value will be passed on the the callback function. The value will be converted to a string.

Parameters
string$valueThe string value that should be processed. Will be passed to the callback as first parameter.
callable$callbackThe data passed to call_user_func().
array$additionalParametersOptional additional parameters passed to the callback as second argument.
Returns
string

Definition at line 747 of file DataMapper.php.

Referenced by DataMapper\getPlainValue().

getPlainValue (   $input,
  $columnMap = null,
  $parseStringValueCallback = null,
array  $parseStringValueCallbackParameters = [] 
)

Returns a plain value, i.e. objects are flattened out if possible. Multi value objects or arrays will be converted to a comma-separated list for use in IN SQL queries.

Parameters
mixed$inputThe value that will be converted.
ColumnMap$columnMapOptional column map for retrieving the date storage format.
callable$parseStringValueCallbackOptional callback method that will be called for string values. Can be used to do database quotation.
array$parseStringValueCallbackParametersAdditional parameters that will be passed to the callabck as second parameter.
Exceptions
InvalidArgumentException
UnexpectedTypeException
Returns
int|string

Definition at line 688 of file DataMapper.php.

References DataMapper\getPlainStringValue(), TypeHandlingUtility\isCoreType(), and TypeHandlingUtility\isValidTypeForMultiValueComparison().

getPreparedQuery ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue = '' 
)
protected

Builds and returns the prepared query, ready to be executed.

Parameters
DomainObjectInterface$parentObject
string$propertyName
string$fieldValue
Returns
Persistence

Definition at line 414 of file DataMapper.php.

References DataMapper\getConstraint(), DataMapper\getDataMap(), DataMapper\getSource(), DataMapper\getType(), QueryInterface\ORDER_ASCENDING, ColumnMap\RELATION_HAS_AND_BELONGS_TO_MANY, and ColumnMap\RELATION_HAS_MANY.

Referenced by DataMapper\countRelated(), and DataMapper\getNonEmptyRelationValue().

getSource ( DomainObjectInterface  $parentObject,
  $propertyName 
)
protected

Builds and returns the source to build a join for a m:n relation.

Parameters
DomainObjectInterface$parentObject
string$propertyName
Returns
$source

Definition at line 474 of file DataMapper.php.

References DataMapper\getDataMap(), DataMapper\getType(), and Query\JCR_JOIN_TYPE_INNER.

Referenced by DataMapper\getPreparedQuery().

getTargetType (   $className,
array  $row 
)

Returns the target type for the given row.

Parameters
string$classNameThe name of the class
array$rowA single array with field_name => value pairs
Returns
string The target type (a class name)

Definition at line 156 of file DataMapper.php.

References DataMapper\getDataMap().

Referenced by DataMapper\map().

getType (   $parentClassName,
  $propertyName 
)

Returns the type of a child object.

Parameters
string$parentClassNameThe class name of the object this proxy is part of
string$propertyNameThe name of the proxied property in it's parent
Exceptions
UnexpectedTypeException
Returns
string The class name of the child object

Definition at line 663 of file DataMapper.php.

Referenced by DataMapper\getPreparedQuery(), and DataMapper\getSource().

injectDataMapFactory ( \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory  $dataMapFactory)
Parameters
\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory$dataMapFactory

Definition at line 104 of file DataMapper.php.

References DataMapper\$dataMapFactory.

injectObjectManager ( \TYPO3\CMS\Extbase\Object\ObjectManagerInterface  $objectManager)
Parameters
\TYPO3\CMS\Extbase\Object\ObjectManagerInterface$objectManager

Definition at line 120 of file DataMapper.php.

References DataMapper\$objectManager.

injectPersistenceSession ( \TYPO3\CMS\Extbase\Persistence\Generic\Session  $persistenceSession)
Parameters
\TYPO3\CMS\Extbase\Persistence\Generic\Session$persistenceSession

Definition at line 96 of file DataMapper.php.

References DataMapper\$persistenceSession.

Parameters
\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory$qomFactory

Definition at line 88 of file DataMapper.php.

References DataMapper\$qomFactory.

injectQueryFactory ( \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface  $queryFactory)
Parameters
\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactoryInterface$queryFactory

Definition at line 112 of file DataMapper.php.

References DataMapper\$queryFactory.

injectReflectionService ( \TYPO3\CMS\Extbase\Reflection\ReflectionService  $reflectionService)
Parameters
\TYPO3\CMS\Extbase\Reflection\ReflectionService$reflectionService

Definition at line 80 of file DataMapper.php.

References DataMapper\$reflectionService.

injectSignalSlotDispatcher ( \TYPO3\CMS\Extbase\SignalSlot\Dispatcher  $signalSlotDispatcher)
Parameters
\TYPO3\CMS\Extbase\SignalSlot\Dispatcher$signalSlotDispatcher

Definition at line 128 of file DataMapper.php.

References DataMapper\$signalSlotDispatcher.

isPersistableProperty (   $className,
  $propertyName 
)

Delegates the call to the Data Map. Returns TRUE if the property is persistable (configured in $TCA)

Parameters
string$classNameThe property name
string$propertyNameThe property name
Returns
bool TRUE if the property is persistable (configured in $TCA)

Definition at line 599 of file DataMapper.php.

References DataMapper\getDataMap().

map (   $className,
array  $rows 
)

Maps the given rows on objects

Parameters
string$classNameThe name of the class
array$rowsAn array of arrays with field_name => value pairs
Returns
array An array of objects of the given class

Definition at line 140 of file DataMapper.php.

References DataMapper\getTargetType(), and DataMapper\mapSingleRow().

mapCoreType (   $type,
  $value 
)
protected

Map value to a core type

Parameters
string$type
mixed$value
Returns

Definition at line 310 of file DataMapper.php.

Referenced by DataMapper\thawProperties().

mapDateTime (   $value,
  $storageFormat = null,
  $targetType = 'DateTime' 
)
protected

Creates a DateTime from an unix timestamp or date/datetime value. If the input is empty, NULL is returned.

Parameters
int | string$valueUnix timestamp or date/datetime value
NULL | string$storageFormatStorage format for native date/datetime fields
NULL | string$targetTypeThe object class name to be created
Returns

Definition at line 324 of file DataMapper.php.

References GeneralUtility\makeInstance().

Referenced by DataMapper\thawProperties().

mapObjectToClassProperty ( DomainObjectInterface  $parentObject,
  $propertyName,
  $fieldValue 
)
protected

Returns the mapped classProperty from the identiyMap or mapResultToPropertyValue()

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
DomainObjectInterface$parentObject
string$propertyName
mixed$fieldValuethe raw field value
Returns
mixed
See also
mapResultToPropertyValue()

Definition at line 500 of file DataMapper.php.

References DataMapper\fetchRelated(), DataMapper\getEmptyRelationValue(), DataMapper\mapResultToPropertyValue(), and DataMapper\propertyMapsByForeignKey().

Referenced by DataMapper\thawProperties().

mapResultToPropertyValue ( DomainObjectInterface  $parentObject,
  $propertyName,
  $result 
)

Returns the given result as property value of the specified property type.

Parameters
DomainObjectInterface$parentObject
string$propertyName
mixed$resultThe result
Returns
mixed

Definition at line 543 of file DataMapper.php.

Referenced by DataMapper\mapObjectToClassProperty(), and DataMapper\thawProperties().

mapSingleRow (   $className,
array  $row 
)
protected

Maps a single row on an object of the given class

Parameters
string$classNameThe name of the target class
array$rowA single array with field_name => value pairs
Returns
object An object of the given class

Definition at line 179 of file DataMapper.php.

References DataMapper\createEmptyObject(), DataMapper\emitAfterMappingSingleRow(), and DataMapper\thawProperties().

Referenced by DataMapper\map().

propertyMapsByForeignKey ( DomainObjectInterface  $parentObject,
  $propertyName 
)
protected

Checks if the relation is based on a foreign key.

Parameters
DomainObjectInterface$parentObject
string$propertyName
Returns
bool TRUE if the property is mapped

Definition at line 529 of file DataMapper.php.

References DataMapper\getDataMap().

Referenced by DataMapper\mapObjectToClassProperty().

thawProperties ( DomainObjectInterface  $object,
array  $row 
)
protected

Member Data Documentation

$dataMapFactory
protected

Definition at line 60 of file DataMapper.php.

Referenced by DataMapper\injectDataMapFactory().

$dataMaps = []
protected

Definition at line 55 of file DataMapper.php.

$objectManager
protected

Definition at line 70 of file DataMapper.php.

Referenced by DataMapper\injectObjectManager().

$pageSelectObject
protected

Definition at line 48 of file DataMapper.php.

$persistenceSession
protected

Definition at line 41 of file DataMapper.php.

Referenced by DataMapper\injectPersistenceSession().

$qomFactory
protected

Definition at line 36 of file DataMapper.php.

Referenced by DataMapper\injectQomFactory().

$queryFactory
protected

Definition at line 65 of file DataMapper.php.

Referenced by DataMapper\injectQueryFactory().

$reflectionService
protected

Definition at line 31 of file DataMapper.php.

Referenced by DataMapper\injectReflectionService().

$signalSlotDispatcher
protected

Definition at line 75 of file DataMapper.php.

Referenced by DataMapper\injectSignalSlotDispatcher().