[+TASK] Extbase (Persistence): Improved build process of a DataMap. You only have...
authorJochen Rau <j.rau@web.de>
Sun, 2 May 2010 09:37:43 +0000 (09:37 +0000)
committerJochen Rau <j.rau@web.de>
Sun, 2 May 2010 09:37:43 +0000 (09:37 +0000)
[+TASK] Extbase (Persistence): The Reflection Service is now injected to the DataMapFactory and the DataMapper.

typo3/sysext/extbase/Classes/Dispatcher.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapFactory.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/Classes/Persistence/QueryFactory.php

index b98120e..eadb655 100644 (file)
@@ -276,6 +276,8 @@ class Tx_Extbase_Dispatcher {
                        $dataMapper->injectIdentityMap($identityMap);
                        $dataMapper->injectSession($persistenceSession);
                        $dataMapper->injectReflectionService(self::$reflectionService);
+                       $dataMapper->injectDataMapFactory(t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapFactory'));
+                       
                        
                        $storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
                        $storageBackend->injectDataMapper($dataMapper);
index 165c095..930399e 100644 (file)
 class Tx_Extbase_Persistence_Mapper_DataMapFactory {
        
        /**
+        * @var Tx_Extbase_Reflection_Service
+        */
+       protected $reflectionService;
+
+       /**
+        * Injects the reflection service
+        *
+        * @param Tx_Extbase_Reflection_Service $reflectionService
+        * @return void
+        */
+       public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
+               $this->reflectionService = $reflectionService;
+       }
+       
+       /**
         * Builds a data map by adding column maps for all the configured columns in the $TCA.
         * It also resolves the type of values the column is holding and the typo of relation the column
         * represents.
@@ -57,27 +72,44 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
                        if (isset($classSettings['mapping']['tableName']) && strlen($classSettings['mapping']['tableName']) > 0) {
                                $tableName = $classSettings['mapping']['tableName'];
                        }
-                       if (isset($classSettings['mapping']['columns']) && is_array($classSettings['mapping']['columns'])) {
-                               $columnMapping = $classSettings['mapping']['columns'];
+                       $classHierachy = array($className) + class_parents($className);
+                       foreach ($classHierachy as $currentClassName) {
+                               if (in_array($currentClassName, array('Tx_Extbase_DomainObject_AbstractEntity', 'Tx_Extbase_DomainObject_AbstractValueObject'))) {
+                                       break;
+                               }
+                               $currentTableName = strtolower($currentClassName);
+                               $currentClassSettings = $extbaseFrameworkConfiguration['persistence']['classes'][$currentClassName];
+                               if ($currentClassSettings !== NULL) {
+                                       if (isset($currentClassSettings['mapping']['columns']) && is_array($currentClassSettings['mapping']['columns'])) {
+                                               $columnMapping = t3lib_div::array_merge_recursive_overrule($columnMapping, $currentClassSettings['mapping']['columns'], 0, FALSE); // FALSE means: do not include empty values form 2nd array
+                                       }
+                               }
                        }
                }
 
                $dataMap = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMap', $className, $tableName, $recordType, $subclasses);
                $dataMap = $this->addMetaDataColumnNames($dataMap, $tableName);
+
                $columnConfigurations = array();
-               foreach ($this->getColumnsDefinition($tableName) as $columnName => $columnDefinition) {
-                       $columnConfigurations[$columnName] = $columnDefinition['config'];
-                       $columnConfigurations[$columnName]['mapOnProperty'] = Tx_Extbase_Utility_Extension::convertUnderscoredToLowerCamelCase($columnName);
-               }
-               $columnConfigurations = t3lib_div::array_merge_recursive_overrule($columnConfigurations, $columnMapping);
-               foreach ($columnConfigurations as $columnName => $columnConfiguration) {
-                       $columnMap = new Tx_Extbase_Persistence_Mapper_ColumnMap($columnName, $columnConfiguration['mapOnProperty']);
-                       $columnMap = $this->setRelations($columnMap, $columnConfiguration);
-                       $dataMap->addColumnMap($columnMap);
+               $classPropertyNames = $this->reflectionService->getClassPropertyNames($className);
+               $tcaColumnsDefinition = $this->getColumnsDefinition($tableName);
+               $tcaColumnsDefinition = t3lib_div::array_merge_recursive_overrule($tcaColumnsDefinition, $columnMapping); // TODO Is this is too powerful?
+               foreach ($tcaColumnsDefinition as $columnName => $columnDefinition) {
+                       if (isset($columnDefinition['mapOnProperty'])) {
+                               $propertyName = $columnDefinition['mapOnProperty'];
+                       } else {
+                               $propertyName = Tx_Extbase_Utility_Extension::convertUnderscoredToLowerCamelCase($columnName);
+                       }
+                       // if (in_array($propertyName, $classPropertyNames)) {
+                               $columnMap = new Tx_Extbase_Persistence_Mapper_ColumnMap($columnName, $propertyName);
+                               $columnMap = $this->setRelations($columnMap, $columnDefinition['config']);
+                               $dataMap->addColumnMap($columnMap);
+                       // }
                }
+               debug($dataMap);
                return $dataMap;
        }
-       
+               
        /**
         * Returns the TCA ctrl section of the specified table; or NULL if not set
         *
index 0448e01..7c01ad5 100644 (file)
@@ -88,7 +88,6 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         */
        public function __construct() {
                $this->queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
-               $this->dataMapFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapFactory');
        }
 
        /**
@@ -122,6 +121,16 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
        }
        
        /**
+        * Injects the DataMap Factory
+        *
+        * @param Tx_Extbase_Persistence_Mapper_DataMapFactory
+        * @return void
+        */
+       public function injectDataMapFactory(Tx_Extbase_Persistence_Mapper_DataMapFactory $dataMapFactory) {
+               $this->dataMapFactory = $dataMapFactory;
+       }
+       
+       /**
         * Sets the query object model factory
         *
         * @param Tx_Extbase_Persistence_QOM_QueryObjectModelFactory $qomFactory
index 6f62dec..28d72f0 100644 (file)
@@ -40,10 +40,16 @@ class Tx_Extbase_Persistence_QueryFactory implements Tx_Extbase_Persistence_Quer
        public function create($className) {
                $persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
 
+               $reflectionService = $persistenceManager->getBackend()->getReflectionService();
+               
+               $dataMapFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapFactory');
+               $dataMapFactory->injectReflectionService($reflectionService);
+
                $dataMapper = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper');
                $dataMapper->injectIdentityMap($persistenceManager->getBackend()->getIdentityMap());
                $dataMapper->injectSession($persistenceManager->getSession());
-               $dataMapper->injectReflectionService($persistenceManager->getBackend()->getReflectionService());
+               $dataMapper->injectReflectionService($reflectionService);
+               $dataMapper->injectDataMapFactory($dataMapFactory);
                
                $querySettings = t3lib_div::makeInstance('Tx_Extbase_Persistence_Typo3QuerySettings');