Extbase:
authorJochen Rau <j.rau@web.de>
Tue, 14 Jul 2009 15:37:06 +0000 (15:37 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 14 Jul 2009 15:37:06 +0000 (15:37 +0000)
* Implemented a static function Tx_Extbase_Dispatcher::getPersistenceManager()
* Changed Repository to invoke Tx_Extbase_Dispatcher::getPersistenceManager()
* These changes should enable the Repository to be called from outside (itemProcFunc); related to #3899

typo3/sysext/extbase/Classes/Dispatcher.php
typo3/sysext/extbase/Classes/Persistence/Repository.php

index 695270e..95f53f1 100644 (file)
@@ -38,6 +38,11 @@ class Tx_Extbase_Dispatcher {
        protected $reflectionService;
 
        /**
+        * @var Tx_Extbase_Persistence_Manager
+        */
+       private static $persistenceManager;
+
+       /**
         * Creates a request an dispatches it to a controller.
         *
         * @param string $content The content
@@ -55,24 +60,7 @@ class Tx_Extbase_Dispatcher {
                $request = $requestBuilder->build();
                $response = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Response');
 
-               $persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session'); // singleton
-               $storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
-               if (isset($configuration['enableAutomaticCacheClearing']) && $configuration['enableAutomaticCacheClearing'] === '1') {
-                       $storageBackend->setAutomaticCacheClearing(TRUE);
-               } else {
-                       $storageBackend->setAutomaticCacheClearing(FALSE);
-               }
-               $dataMapper = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper');
-
-               $persistenceBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Backend', $persistenceSession, $storageBackend); // singleton
-               $persistenceBackend->injectDataMapper($dataMapper);
-               $persistenceBackend->injectIdentityMap(t3lib_div::makeInstance('Tx_Extbase_Persistence_IdentityMap'));
-               $persistenceBackend->injectQOMFactory(t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_QueryObjectModelFactory', $storageBackend, $dataMapper));
-               $persistenceBackend->injectValueFactory(t3lib_div::makeInstance('Tx_Extbase_Persistence_ValueFactory'));
-
-               $persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager'); // singleton
-               $persistenceManager->injectBackend($persistenceBackend);
-               $persistenceManager->injectSession($persistenceSession);
+               $persistenceManager = self::getPersistenceManager($configuration);
 
                $dispatchLoopCount = 0;
                while (!$request->isDispatched()) {
@@ -156,6 +144,39 @@ class Tx_Extbase_Dispatcher {
        }
 
        /**
+        * This function prepares and returns the Persistance Manager
+        *
+        * @param array $configuration The given configuration
+        * @return Tx_Extbase_Persistence_Manager A (singleton) instance of the Persistence Manager
+        */
+       public static function getPersistenceManager(array $configuration = array()) {
+               if (self::$persistenceManager === NULL) {
+                       $persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session'); // singleton
+                       $storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
+                       if (is_array($configuration) && isset($configuration['enableAutomaticCacheClearing']) && $configuration['enableAutomaticCacheClearing'] === '1') {
+                               $storageBackend->setAutomaticCacheClearing(TRUE);
+                       } else {
+                               $storageBackend->setAutomaticCacheClearing(FALSE);
+                       }
+                       $dataMapper = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper'); // singleton
+
+                       $persistenceBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Backend', $persistenceSession, $storageBackend); // singleton
+                       $persistenceBackend->injectDataMapper($dataMapper);
+                       $persistenceBackend->injectIdentityMap(t3lib_div::makeInstance('Tx_Extbase_Persistence_IdentityMap'));
+                       $persistenceBackend->injectQOMFactory(t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_QueryObjectModelFactory', $storageBackend, $dataMapper));
+                       $persistenceBackend->injectValueFactory(t3lib_div::makeInstance('Tx_Extbase_Persistence_ValueFactory'));
+
+                       $persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager'); // singleton
+                       $persistenceManager->injectBackend($persistenceBackend);
+                       $persistenceManager->injectSession($persistenceSession);
+
+                       self::$persistenceManager = $persistenceManager;
+               }
+
+               return self::$persistenceManager;
+       }
+
+       /**
         * Loads php files containing classes or interfaces found in the classes directory of
         * an extension.
         *
index ad1809c..d7869d7 100644 (file)
@@ -50,7 +50,7 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi
         */
        public function __construct() {
                $this->queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
-               $this->persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager'); // singleton; must have been initialized before
+               $this->persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
        }
 
        /**