[TASK] Deprecate usage of $GLOBALS['typo3CacheManager'] 01/28101/7
authorHelmut Hummel <helmut.hummel@typo3.org>
Thu, 6 Mar 2014 10:53:07 +0000 (11:53 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 7 Mar 2014 18:44:14 +0000 (19:44 +0100)
* Replace all instances of $GLOBALS['typo3CacheManager']
  in the core with a makeInstance call.
* Adapt the tests.
* Make use of dependency injection where possible.
* Add compatibility layer with deprecation message
  for $GLOBALS['typo3CacheManager'] and $GLOBALS['typo3CacheFactory']

Resolves: #56597
Releases: 6.2
Change-Id: Idb035723626b24cfd768204bf24987171f5b0feb
Reviewed-on: https://review.typo3.org/28101
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
42 files changed:
typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php
typo3/sysext/backend/Classes/Sprite/SpriteManager.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/Cache/Cache.php
typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php [new file with mode: 0644]
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Localization/LocalizationFactory.php
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/RootlineUtility.php
typo3/sysext/core/Tests/Integrity/IntegrityTest.php
typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php
typo3/sysext/core/Tests/Unit/Localization/Parser/LocallangXmlParserTest.php
typo3/sysext/core/Tests/Unit/Localization/Parser/XliffParserTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Classes/Object/Container/ClassInfoCache.php
typo3/sysext/extbase/Classes/Object/Container/Container.php
typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php
typo3/sysext/extbase/Tests/Unit/Scheduler/TaskExecutorTest.php
typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php
typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
typo3/sysext/fluid/Classes/View/StandaloneView.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/indexed_search/Classes/Controller/IndexedPagesController.php
typo3/sysext/install/Classes/Controller/AbstractController.php
typo3/sysext/install/Classes/Controller/Action/Step/DatabaseConnect.php
typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php
typo3/sysext/install/Classes/Service/ClearCacheService.php
typo3/sysext/install/Classes/View/StandaloneView.php
typo3/sysext/scheduler/Classes/Task/CachingFrameworkGarbageCollectionTask.php
typo3/sysext/scheduler/Tests/Unit/Task/CachingFrameworkGarbageCollectionTest.php
typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
typo3/sysext/workspaces/Classes/Service/GridDataService.php

index 109960b..3127aa1 100644 (file)
@@ -260,7 +260,7 @@ class FrontendBackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\B
         * @return integer The number of pages for this page in the table "cache_pages
         */
        public function extGetNumberOfCachedPages($pageId) {
-               $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+               $pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
                $pageCacheEntries = $pageCache->getByTag('pageId_' . (int)$pageId);
                return count($pageCacheEntries);
        }
index 66cc35b..536a9ea 100644 (file)
@@ -62,7 +62,7 @@ class SpriteManager {
                if (!static::isInitialized()) {
                        $cacheIdentifier = static::getCacheIdentifier();
                        /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       $codeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core');
                        if ($codeCache->has($cacheIdentifier)) {
                                $codeCache->requireOnce($cacheIdentifier);
                        } else {
@@ -117,7 +117,7 @@ class SpriteManager {
                $cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = ';
                $cacheFileContent .= var_export($iconNames, TRUE) . ';';
                /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
+               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
        }
 
        /**
index 7aa5777..9e00ffa 100644 (file)
@@ -1092,7 +1092,7 @@ class BackendUtility {
         * @return      void
         */
        static public function storeHash($hash, $data, $ident) {
-               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), 0);
+               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), 0);
        }
 
        /**
@@ -1102,12 +1102,12 @@ class BackendUtility {
         * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
         *
         * @param string $hash The hash-string which was used to store the data value
-        * @param integer $expTime Variabele is not used in the function
+        * @param integer $expTime Variable is not used in the function
         * @return mixed The "data" from the cache
         */
        static public function getHash($hash, $expTime = 0) {
                $hashContent = NULL;
-               $cacheEntry = $GLOBALS['typo3CacheManager']->getCache('cache_hash')->get($hash);
+               $cacheEntry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->get($hash);
                if ($cacheEntry) {
                        $hashContent = $cacheEntry;
                }
@@ -1892,7 +1892,7 @@ class BackendUtility {
                        return $GLOBALS['TCA'][$table]['columns'][$col]['label'];
                }
                if ($printAllWrap) {
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('The third parameter of getItemLabel() is deprecated with TYPO3 CMS 6.2 and will be removed two versions later.');
+                       GeneralUtility::deprecationLog('The third parameter of getItemLabel() is deprecated with TYPO3 CMS 6.2 and will be removed two versions later.');
                        $parts = explode('|', $printAllWrap);
                        return $parts[0] . $col . $parts[1];
                }
index 694f295..eabf77c 100644 (file)
@@ -23,6 +23,8 @@ namespace TYPO3\CMS\Core\Cache;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * A cache handling helper class
  *
@@ -36,22 +38,33 @@ class Cache {
        static protected $isCachingFrameworkInitialized = FALSE;
 
        /**
+        * @var CacheManager
+        */
+       static protected $cacheManager;
+
+       /**
+        * @var CacheFactory
+        */
+       static protected $cacheFactory;
+
+       /**
         * Initializes the caching framework by loading the cache manager and factory
         * into the global context.
         *
-        * @return void
+        * @return CacheManager
         */
        static public function initializeCachingFramework() {
                if (!self::isCachingFrameworkInitialized()) {
                        // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-                       $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $GLOBALS['typo3CacheManager']);
-                       $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+                       self::$cacheManager = new CacheManager();
+                       GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
+                       self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                        // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-                       $GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $GLOBALS['typo3CacheManager']);
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', $GLOBALS['typo3CacheFactory']);
+                       self::$cacheFactory = new CacheFactory('production', self::$cacheManager);
+                       GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
                        self::$isCachingFrameworkInitialized = TRUE;
                }
+               return self::$cacheManager;
        }
 
        /**
@@ -61,9 +74,6 @@ class Cache {
         * @return boolean True if caching framework is initialized
         */
        static public function isCachingFrameworkInitialized() {
-               if (!self::$isCachingFrameworkInitialized && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof \TYPO3\CMS\Core\Cache\CacheFactory) {
-                       self::$isCachingFrameworkInitialized = TRUE;
-               }
                return self::$isCachingFrameworkInitialized;
        }
 
@@ -75,8 +85,10 @@ class Cache {
         */
        static public function flagCachingFrameworkForReinitialization() {
                self::$isCachingFrameworkInitialized = FALSE;
-               unset($GLOBALS['typo3CacheManager']);
-               unset($GLOBALS['typo3CacheFactory']);
+               GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
+               GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
+               self::$cacheManager = NULL;
+               self::$cacheFactory = NULL;
        }
 
        /**
@@ -90,7 +102,7 @@ class Cache {
        static public function getDatabaseTableDefinitions() {
                $tableDefinitions = '';
                foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
-                       $backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
+                       $backend = self::$cacheManager->getCache($cacheName)->getBackend();
                        if (method_exists($backend, 'getTableDefinitions')) {
                                $tableDefinitions .= LF . $backend->getTableDefinitions();
                        }
@@ -107,7 +119,7 @@ class Cache {
         * @return array
         */
        public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString, $extensionKey) {
-               $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+               self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                $sqlString[] = static::getDatabaseTableDefinitions();
                return array('sqlString' => $sqlString, 'extensionKey' => $extensionKey);
        }
diff --git a/typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php b/typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php
new file mode 100644 (file)
index 0000000..8693d93
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+namespace TYPO3\CMS\Core\Compatibility;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2014 Helmut Hummel <helmut.hummel@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Class CacheManagerGlobal will be instanciated and
+ * passed to $GLOBALS['typo3CacheManager'] to not break
+ * extension code
+ *
+ */
+class GlobalObjectDeprecationDecorator {
+
+       /**
+        * @var string
+        */
+       protected $className;
+
+       /**
+        * @var string
+        */
+       protected $deprecationMessage;
+
+       /**
+        * @param string $className
+        * @param string $deprecationMessage
+        */
+       public function __construct($className, $deprecationMessage = NULL) {
+               $this->className = $className;
+               $this->deprecationMessage = $deprecationMessage ?: 'Usage of $GLOBALS[\'typo3CacheManager\'] and $GLOBALS[\'typo3CacheFactory\'] are deprecated since 6.2 will be removed in two versions. Use \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\'' . $this->className . '\') or dependency injection to access the singletons.';
+       }
+
+       /**
+        * Calls decorated object and issues a deprecation message
+        *
+        * @param string $methodName
+        * @param array $arguments
+        * @return mixed
+        * @deprecated
+        */
+       public function __call($methodName, $arguments) {
+               GeneralUtility::deprecationLog($this->deprecationMessage);
+               $decoratedObject = GeneralUtility::makeInstance($this->className);
+               return call_user_func_array(array($decoratedObject, $methodName), $arguments);
+       }
+}
\ No newline at end of file
index c9942f7..85395c9 100644 (file)
@@ -480,9 +480,10 @@ class Bootstrap {
         * @return Bootstrap
         */
        protected function initializeCachingFramework() {
-               // @todo Please deuglify
-               \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
-               $this->setEarlyInstance('TYPO3\CMS\Core\Cache\CacheManager', $GLOBALS['typo3CacheManager']);
+               $this->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework());
+               // @deprecated since 6.2 will be removed in two versions
+               $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               $GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheFactory');
                return $this;
        }
 
@@ -698,7 +699,7 @@ class Bootstrap {
         * @return Bootstrap
         */
        protected function setFinalCachingFrameworkCacheConfiguration() {
-               $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+               $this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                return $this;
        }
 
@@ -896,7 +897,7 @@ class Bootstrap {
        public function loadCachedTca() {
                $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
                /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-               $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+               $codeCache = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core');
                if ($codeCache->has($cacheIdentifier)) {
                        // substr is necessary, because the php frontend wraps php code around the cache value
                        $GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
index 2a065a5..503dc0b 100644 (file)
@@ -6538,18 +6538,6 @@ class DataHandler {
        }
 
        /**
-        * Unlink (delete) core cache files
-        *
-        * @return void
-        * @deprecated since 6.0, will be removed in two versions, use the cache manager directly instead
-        * @todo Define visibility
-        */
-       public function removeCacheFiles() {
-               GeneralUtility::logDeprecatedFunction();
-               $GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
-       }
-
-       /**
         * Returns array, $CPtable, of pages under the $pid going down to $counter levels.
         * Selecting ONLY pages which the user has read-access to!
         *
@@ -6957,13 +6945,13 @@ class DataHandler {
                                                        // point to real pages and caches at all. Flushing caches for
                                                        // those records does not make sense and decreases performance
                                                        if ($pageId >= 0) {
-                                                               $GLOBALS['typo3CacheManager']->flushCachesByTag('pageId_' . $pageId);
+                                                               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag('pageId_' . $pageId);
                                                        }
                                                }
                                        }
                                        // Delete cache for current table and record
-                                       $GLOBALS['typo3CacheManager']->flushCachesByTag($table);
-                                       $GLOBALS['typo3CacheManager']->flushCachesByTag($table . '_' . $uid);
+                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag($table);
+                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag($table . '_' . $uid);
                                }
                        }
                        // Clear cache for pages entered in TSconfig:
@@ -7031,13 +7019,13 @@ class DataHandler {
                switch (strtolower($cacheCmd)) {
                        case 'pages':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
-                                       $GLOBALS['typo3CacheManager']->flushCachesInGroup('pages');
+                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
                                }
                                break;
                        case 'all':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
                                        // Clear cache group "all" of caching framework caches
-                                       $GLOBALS['typo3CacheManager']->flushCachesInGroup('all');
+                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('all');
                                        if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
                                                $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
                                        }
@@ -7058,7 +7046,7 @@ class DataHandler {
                        case 'temp_cached':
                        case 'system':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')) {
-                                       $GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
                                }
                                break;
                }
@@ -7092,7 +7080,7 @@ class DataHandler {
                // process caching framwork operations
                if (count($tagsToFlush) > 0) {
                        foreach ($tagsToFlush as $tag) {
-                               $GLOBALS['typo3CacheManager']->flushCachesInGroupByTag('pages', $tag);
+                               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroupByTag('pages', $tag);
                        }
                }
 
@@ -7213,7 +7201,7 @@ class DataHandler {
         */
        public function internal_clearPageCache() {
                GeneralUtility::logDeprecatedFunction();
-               $GLOBALS['typo3CacheManager']->flushCachesInGroup('pages');
+               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
        }
 
        /**
@@ -7323,7 +7311,7 @@ class DataHandler {
         * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
         */
        protected function getMemoryCache() {
-               return $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
        }
 
        /**
index ad5e7b1..ef9d135 100644 (file)
@@ -71,7 +71,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        protected function initializeCache() {
-               $this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('l10n');
+               $this->cacheInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n');
        }
 
        /**
index f88446e..6337fb2 100644 (file)
@@ -393,7 +393,7 @@ class TemplateService {
         * @return array Returns the unmatched array $currentPageData if found cached in "cache_pagesection". Otherwise FALSE is returned which means that the array must be generated and stored in the cache
         */
        public function getCurrentPageData() {
-               return $GLOBALS['typo3CacheManager']->getCache('cache_pagesection')->get((int)$GLOBALS['TSFE']->id . '_' . GeneralUtility::md5int($GLOBALS['TSFE']->MP));
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pagesection')->get((int)$GLOBALS['TSFE']->id . '_' . GeneralUtility::md5int($GLOBALS['TSFE']->MP));
        }
 
        /**
@@ -520,7 +520,7 @@ class TemplateService {
                                // Only save the data if we're not simulating by hidden/starttime/endtime
                                $mpvarHash = GeneralUtility::md5int($GLOBALS['TSFE']->MP);
                                /** @var $pageSectionCache \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface */
-                               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                               $pageSectionCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pagesection');
                                $pageSectionCache->set((int)$GLOBALS['TSFE']->id . '_' . $mpvarHash, $cc, array(
                                        'pageId_' . (int)$GLOBALS['TSFE']->id,
                                        'mpvarHash_' . $mpvarHash
index 2d0b70f..91b4238 100644 (file)
@@ -67,6 +67,23 @@ class ExtensionManagementUtility {
                static::$packageManager = $packageManager;
        }
 
+       /**
+        * @var \TYPO3\CMS\Core\Cache\CacheManager
+        */
+       static protected $cacheManager;
+
+       /**
+        * Getter for the cache manager
+        *
+        * @return \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
+        */
+       static protected function getCacheManager() {
+               if (static::$cacheManager === NULL) {
+                       static::$cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               }
+               return static::$cacheManager;
+       }
+
        /**************************************
         *
         * PATHS and other evaluation
@@ -1446,7 +1463,7 @@ tt_content.' . $key . $prefix . ' {
                if ($allowCaching) {
                        $cacheIdentifier = self::getExtLocalconfCacheIdentifier();
                        /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       $codeCache = self::getCacheManager()->getCache('cache_core');
                        if ($codeCache->has($cacheIdentifier)) {
                                $codeCache->requireOnce($cacheIdentifier);
                        } else {
@@ -1516,7 +1533,7 @@ tt_content.' . $key . $prefix . ' {
                $phpCodeToCache = implode(LF, $phpCodeToCache);
                // Remove all start and ending php tags from content
                $phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
-               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtLocalconfCacheIdentifier(), $phpCodeToCache);
+               self::getCacheManager()->getCache('cache_core')->set(self::getExtLocalconfCacheIdentifier(), $phpCodeToCache);
        }
 
        /**
@@ -1546,7 +1563,7 @@ tt_content.' . $key . $prefix . ' {
                if ($allowCaching) {
                        $cacheIdentifier = static::getBaseTcaCacheIdentifier();
                        /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       $codeCache = self::getCacheManager()->getCache('cache_core');
                        if ($codeCache->has($cacheIdentifier)) {
                                // substr is necessary, because the php frontend wraps php code around the cache value
                                $GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
@@ -1600,7 +1617,7 @@ tt_content.' . $key . $prefix . ' {
         */
        static protected function createBaseTcaCacheFile() {
                /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-               $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+               $codeCache = self::getCacheManager()->getCache('cache_core');
                $codeCache->set(static::getBaseTcaCacheIdentifier(), serialize($GLOBALS['TCA']));
        }
 
@@ -1630,7 +1647,7 @@ tt_content.' . $key . $prefix . ' {
                        self::$extTablesWasReadFromCacheOnce = TRUE;
                        $cacheIdentifier = self::getExtTablesCacheIdentifier();
                        /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       $codeCache = self::getCacheManager()->getCache('cache_core');
                        if ($codeCache->has($cacheIdentifier)) {
                                $codeCache->requireOnce($cacheIdentifier);
                        } else {
@@ -1707,7 +1724,7 @@ tt_content.' . $key . $prefix . ' {
                $phpCodeToCache = implode(LF, $phpCodeToCache);
                // Remove all start and ending php tags from content
                $phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
-               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtTablesCacheIdentifier(), $phpCodeToCache);
+               self::getCacheManager()->getCache('cache_core')->set(self::getExtTablesCacheIdentifier(), $phpCodeToCache);
        }
 
        /**
@@ -1788,7 +1805,7 @@ tt_content.' . $key . $prefix . ' {
         * @return void
         */
        static public function removeCacheFiles() {
-               $GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+               self::getCacheManager()->flushCachesInGroup('system');
        }
 
        /**
index fa25704..090461b 100644 (file)
@@ -4396,6 +4396,33 @@ Connection: close
        }
 
        /**
+        * Removes the instance of a singleton class to be returned by makeInstance.
+        *
+        * Warning:
+        * This is NOT a public API method and must not be used in own extensions!
+        * This methods exists mostly for unit tests to inject a mock of a singleton class.
+        * If you use this, make sure to always combine this with getSingletonInstances()
+        * and resetSingletonInstances() in setUp() and tearDown() of the test class.
+        *
+        * @see makeInstance
+        * @throws \InvalidArgumentException
+        * @param string $className
+        * @param \TYPO3\CMS\Core\SingletonInterface $instance
+        * @return void
+        * @internal
+        */
+       static public function removeSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance) {
+               self::checkInstanceClassName($className, $instance);
+               if (!isset(self::$singletonInstances[$className])) {
+                       throw new \InvalidArgumentException('No Instance registered for ' . $className . '.', 1394099179);
+               }
+               if ($instance !== self::$singletonInstances[$className]) {
+                       throw new \InvalidArgumentException('The instance you are trying to remove has not been registered before.', 1394099256);
+               }
+               unset(self::$singletonInstances[$className]);
+       }
+
+       /**
         * Set a group of singleton instances. Similar to setSingletonInstance(),
         * but multiple instances can be set.
         *
index 3203ba7..4e551c0 100644 (file)
@@ -162,7 +162,7 @@ class RootlineUtility {
                        }
                }
                if (self::$cache === NULL) {
-                       self::$cache = $GLOBALS['typo3CacheManager']->getCache('cache_rootline');
+                       self::$cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_rootline');
                }
                self::$rootlineFields = array_merge(self::$rootlineFields, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'], TRUE));
                self::$rootlineFields = array_unique(self::$rootlineFields);
index 6fa1ce0..23fb5a3 100644 (file)
@@ -35,17 +35,6 @@ namespace TYPO3\CMS\Core\Tests\Integrity;
 class IntegrityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * This test fails if some test before mocked or substituted
-        * $GLOBALS['typo3CacheManager'] but did not reconstitute correctly.
-        *
-        * @test
-        */
-       public function globalsTypo3CacheManagerIsInstanceOfCoreCacheManager() {
-               $this->assertTrue(is_object($GLOBALS['typo3CacheManager']));
-               $this->assertTrue($GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager);
-       }
-
-       /**
         * This test fails if some test before called
         * \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances() without a proper
         * backup via \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances()
@@ -58,6 +47,7 @@ class IntegrityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function standardSingletonIsRegistered() {
                $registeredSingletons = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-               $this->assertArrayHasKey('TYPO3\CMS\Core\Cache\CacheManager', $registeredSingletons);
+               $this->assertArrayHasKey('TYPO3\\CMS\\Core\\Cache\\CacheManager', $registeredSingletons);
+               $this->assertTrue($registeredSingletons['TYPO3\\CMS\\Core\\Cache\\CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager);
        }
 }
index d5c70e3..9c1e46a 100644 (file)
@@ -54,11 +54,11 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock(
+               $mockCacheManager = $this->getMock(
                        'TYPO3\\CMS\\Core\\Cache\\CacheManager',
                        array('getCache')
                );
-               $GLOBALS['typo3CacheManager']
+               $mockCacheManager
                        ->expects($this->any())
                        ->method('getCache')
                        ->will($this->returnValue($mockCache));
@@ -69,6 +69,7 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $mockCache
                        ->expects($this->once())
                        ->method('get');
+               $bootstrapInstance->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
                $bootstrapInstance->loadCachedTca();
        }
 
@@ -91,11 +92,11 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock(
+               $mockCacheManager = $this->getMock(
                        'TYPO3\\CMS\\Core\\Cache\\CacheManager',
                        array('getCache')
                );
-               $GLOBALS['typo3CacheManager']
+               $mockCacheManager
                        ->expects($this->any())
                        ->method('getCache')
                        ->will($this->returnValue($mockCache));
@@ -106,6 +107,7 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $mockCache
                        ->expects($this->once())
                        ->method('set');
+               $bootstrapInstance->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
                $bootstrapInstance->loadCachedTca();
        }
 }
index caaeda1..b73be56 100644 (file)
@@ -63,7 +63,7 @@ class LocallangXmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xml';
                \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
                        // Clear localization cache
-               $GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
        }
 
        /**
index bd41ff9..7dacbfa 100644 (file)
@@ -70,7 +70,7 @@ class XliffParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xlf';
                \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
                        // Clear localization cache
-               $GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
        }
 
        /**
index f5f0912..74e24e7 100644 (file)
@@ -46,7 +46,6 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
        public function setUp() {
                parent::setUp();
                $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-               \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(
                        'TYPO3\\CMS\\Core\\Resource\\FileRepository',
                        $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository')
index df7cbe2..260560e 100644 (file)
@@ -25,6 +25,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  ***************************************************************/
 
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for ExtensionManagementUtility
@@ -40,15 +41,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        protected $singletonInstances = array();
 
        /**
-        * phpunit still needs some globals that are
-        * reconstructed before $backupGlobals is handled. Those
-        * important globals are handled in tearDown() directly.
-        *
-        * @var array
-        */
-       protected $globals = array();
-
-       /**
         * Absolute path to files that must be removed
         * after a test - handled in tearDown
         *
@@ -71,9 +63,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
        public function tearDown() {
                ExtensionManagementUtility::clearExtensionKeyMap();
-               foreach ($this->globals as $key => $value) {
-                       $GLOBALS[$key] = unserialize($value);
-               }
                foreach ($this->testFilesToDelete as $absoluteFileName) {
                        \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
                }
@@ -81,6 +70,7 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/test_ext/', TRUE);
                }
                ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager(NULL);
                $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->backUpPackageManager);
                \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
                parent::tearDown();
@@ -98,6 +88,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        eval(
                                'namespace ' . __NAMESPACE__ . ';' .
                                'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
+                               '  static public function setCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = NULL) {'.
+                               '    static::$cacheManager = $cacheManager;'.
+                               '  }'.
                                '  public static function getPackageManager() {' .
                                '    return static::$packageManager;' .
                                '  }' .
@@ -748,8 +741,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         * @test
         */
        public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->never())->method('getCache');
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
                ExtensionManagementUtility::loadExtLocalconf(FALSE);
        }
@@ -765,8 +759,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
                $mockCache->expects($this->once())->method('requireOnce');
                ExtensionManagementUtility::loadExtLocalconf(TRUE);
@@ -880,8 +875,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
                ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
        }
@@ -900,8 +896,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())
                        ->method('set')
                        ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
@@ -919,8 +916,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
                $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
                ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
@@ -948,8 +946,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         * @test
         */
        public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied() {
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->never())->method('getCache');
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                ExtensionManagementUtility::loadBaseTca(FALSE);
        }
 
@@ -964,8 +963,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
                $mockCache->expects($this->once())->method('get');
                ExtensionManagementUtility::loadBaseTca(TRUE);
@@ -994,8 +994,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
                ExtensionManagementUtility::loadBaseTca(TRUE);
@@ -1012,8 +1013,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
                ExtensionManagementUtility::loadBaseTca();
@@ -1041,8 +1043,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         * @test
         */
        public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->never())->method('getCache');
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
                ExtensionManagementUtility::loadExtLocalconf(FALSE);
        }
@@ -1058,8 +1061,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
                $mockCache->expects($this->once())->method('requireOnce');
                // Reset the internal cache access tracking variable of extMgm
@@ -1092,8 +1096,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
                ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
        }
@@ -1113,8 +1118,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())
                        ->method('set')
                        ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
@@ -1132,8 +1138,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        '',
                        FALSE
                );
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
                $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
                ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
@@ -1160,8 +1167,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         * @test
         */
        public function removeCacheFilesFlushesSystemCaches() {
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
-               $GLOBALS['typo3CacheManager']->expects($this->once())->method('flushCachesInGroup')->with('system');
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
+               $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
+               ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
                ExtensionManagementUtility::removeCacheFiles();
        }
 
index 4a15373..49d7839 100644 (file)
@@ -2480,11 +2480,11 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $file = PATH_site . 'typo3temp/' . $unique . '.xml';
                Utility\GeneralUtility::writeFileToTypo3tempDir($file, $xml);
                // Make sure there is no cached version of the label
-               $GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+               Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
                // Get default value
                $defaultLL = Utility\GeneralUtility::readLLfile('EXT:lang/locallang_core.xlf', 'default');
                // Clear language cache again
-               $GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+               Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
                // Set override file
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xlf'][$unique] = $file;
                /** @var $store \TYPO3\CMS\Core\Localization\LanguageStore */
index a4683da..48e2f46 100644 (file)
@@ -156,7 +156,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface {
         * @see initialize()
         */
        protected function initializeCache() {
-               $this->cacheManager = $GLOBALS['typo3CacheManager'];
+               $this->cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
        }
 
        /**
index cece0c2..9e22132 100644 (file)
@@ -89,6 +89,6 @@ class ClassInfoCache {
         * Initialize the TYPO3 second level cache
         */
        private function initializeLevel2Cache() {
-               $this->level2Cache = $GLOBALS['typo3CacheManager']->getCache('extbase_object');
+               $this->level2Cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('extbase_object');
        }
 }
index b3f852c..8f75a90 100644 (file)
@@ -152,7 +152,7 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
                        return $this;
                }
                if ($className === 'TYPO3\\CMS\\Core\\Cache\\CacheManager') {
-                       return $GLOBALS['typo3CacheManager'];
+                       return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
                }
                if ($className === 'TYPO3\\CMS\\Core\\Package\\PackageManager') {
                        return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
index e6651bd..f9776af 100644 (file)
@@ -101,7 +101,7 @@ class TaskExecutor implements \TYPO3\CMS\Core\SingletonInterface {
                }
                // initialize reflection
                $reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
-               $reflectionService->setDataCache($GLOBALS['typo3CacheManager']->getCache('extbase_reflection'));
+               $reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('extbase_reflection'));
                if (!$reflectionService->isInitialized()) {
                        $reflectionService->initialize();
                }
index f0500f7..8d8b9df 100644 (file)
@@ -28,6 +28,10 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+require_once __DIR__ . '/Fixtures/MockACommandController.php';
+
 /**
  * TaskExecutor Test Class
  */
@@ -39,11 +43,6 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $controller;
 
        /**
-        * @var \TYPO3\CMS\Core\Cache\CacheManager|\PHPUnit_Framework_MockObject_MockObject
-        */
-       protected $cacheManager;
-
-       /**
         * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
         */
        protected $objectManager;
@@ -63,25 +62,31 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        protected $taskExecuter;
 
+       /**
+        * Backup of current singleton instances
+        */
+       protected $singletonInstances;
+
        public function setUp() {
                if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
                        $this->markTestSkipped('Tests need EXT:scheduler loaded.');
                }
-               $this->controller = $this->getAccessibleMock('TYPO3\CMS\Extbase\Tests\MockACommandController', array('dummy'));
-               $this->controller->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
-               $this->controller->_set('objectManager', $this->objectManager);
-
-               $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\CMS\Extbase\Tests\MockACommandController', 'funcA');
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $nullBackend = new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production');
                $variableFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('foo', $nullBackend);
+               $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('dummy', 'getCache'));
+               $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
+               GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 
-               $this->cacheManager = $this->getMock('TYPO3\CMS\Core\Cache\CacheManager', array('dummy', 'getCache'));
-               $this->cacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
-               $GLOBALS['typo3CacheManager'] = $this->cacheManager;
+               $this->controller = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', array('dummy'));
+               $this->controller->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
+               $this->controller->_set('objectManager', $this->objectManager);
 
-               $this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
-               $this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('dummy', 'getCommandByIdentifier'));
-               $this->configurationManager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
+               $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', 'funcA');
+
+               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('dummy'));
+               $this->commandManager = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager', array('dummy', 'getCommandByIdentifier'));
+               $this->configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
 
                $this->configurationManager
                        ->expects($this->once())
@@ -95,16 +100,21 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        ->will($this->returnValue($command));
        }
 
+       public function tearDown() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+               parent::tearDown();
+       }
+
        /**
         * @test
         * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
         */
        public function executeDispatchesTheRightCommandControllerAndCommandAction() {
-               $dispatcher = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Dispatcher', array('resolveController'), array($this->objectManager));
+               $dispatcher = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher', array('resolveController'), array($this->objectManager));
                $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($this->controller));
-               $dispatcher->_set('signalSlotDispatcher', $this->objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'));
+               $dispatcher->_set('signalSlotDispatcher', $this->objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'));
 
-               $this->taskExecuter = $this->getAccessibleMock('TYPO3\CMS\Extbase\Scheduler\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
+               $this->taskExecuter = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
                $this->taskExecuter->expects($this->any())->method('getDispatcher')->will($this->returnValue($dispatcher));
                $this->taskExecuter->_set('objectManager', $this->objectManager);
                $this->taskExecuter->_set('commandManager', $this->commandManager);
index 4c21b1c..efd77e6 100644 (file)
@@ -71,7 +71,7 @@ class ConfigurationUtility implements \TYPO3\CMS\Core\SingletonInterface {
                /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
                $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
                $configurationManager->setLocalConfigurationValueByPath('EXT/extConf/' . $extensionKey, serialize($configuration));
-               $GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+               \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
        }
 
        /**
index 878992c..12283fa 100644 (file)
@@ -26,6 +26,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * Extension Manager Install Utility
  *
@@ -82,6 +83,12 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
        protected $packageManager;
 
        /**
+        * @var \TYPO3\CMS\Core\Cache\CacheManager
+        * @inject
+        */
+       protected $cacheManager;
+
+       /**
         * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
         * @inject
         */
@@ -123,7 +130,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $this->processRuntimeDatabaseUpdates($extensionKey);
                $this->saveDefaultConfiguration($extension['key']);
                if ($extension['clearcacheonload']) {
-                       $GLOBALS['typo3CacheManager']->flushCaches();
+                       $this->cacheManager->flushCaches();
                }
        }
 
@@ -290,7 +297,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        public function reloadCaches() {
-               $GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+               $this->cacheManager->flushCachesInGroup('system');
                \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->reloadTypo3LoadedExtAndClassLoaderAndExtLocalconf()->loadExtensionTables();
        }
 
index a0e2c95..1b128e1 100644 (file)
@@ -45,7 +45,7 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $fakedExtensions = array();
 
        /**
-        * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Utility\InstallUtility
+        * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Utility\InstallUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
        protected $installMock;
 
@@ -142,8 +142,9 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function installCallsFlushCachesIfClearCacheOnLoadIsSet() {
                $this->extensionData['clearcacheonload'] = TRUE;
-               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
-               $GLOBALS['typo3CacheManager']->expects($this->once())->method('flushCaches');
+               $cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               $cacheManagerMock->expects($this->once())->method('flushCaches');
+               $this->installMock->_set('cacheManager', $cacheManagerMock);
                $this->installMock->install($this->extensionKey);
        }
 
index ae241c7..6a94fcd 100644 (file)
@@ -79,7 +79,7 @@ abstract class AbstractTemplateView implements \TYPO3\CMS\Extbase\Mvc\View\ViewI
         */
        public function injectTemplateCompiler(\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler) {
                $this->templateCompiler = $templateCompiler;
-               $this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+               $this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
        }
 
        /**
index 8dbbfc8..8bda6a8 100644 (file)
@@ -89,7 +89,7 @@ class StandaloneView extends \TYPO3\CMS\Fluid\View\AbstractTemplateView {
                $this->setControllerContext($controllerContext);
                $this->templateCompiler = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler');
                // singleton
-               $this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+               $this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
        }
 
        /**
index a99ab0e..f2bbc8a 100644 (file)
@@ -2144,7 +2144,7 @@ class ContentObjectRenderer {
        public function stdWrap_cacheRead($content = '', $conf = array()) {
                if (!empty($conf['cache.']['key'])) {
                        /** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
-                       $cacheFrontend = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                       $cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
                        if ($cacheFrontend && $cacheFrontend->has($conf['cache.']['key'])) {
                                $content = $cacheFrontend->get($conf['cache.']['key']);
                                $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
@@ -3385,7 +3385,7 @@ class ContentObjectRenderer {
        public function stdWrap_cacheStore($content = '', $conf = array()) {
                if (!empty($conf['cache.']['key'])) {
                        /** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
-                       $cacheFrontend = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                       $cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
                        if ($cacheFrontend) {
                                $tags = !empty($conf['cache.']['tags']) ? GeneralUtility::trimExplode(',', $conf['cache.']['tags']) : array();
                                if (strtolower($conf['cache.']['lifetime']) == 'unlimited') {
index e8a356d..6b26ed3 100644 (file)
@@ -897,7 +897,7 @@ class TypoScriptFrontendController {
         * @return void
         */
        protected function initCaches() {
-               $this->pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+               $this->pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
        }
 
        /**
@@ -4514,7 +4514,7 @@ if (version == "n3") {
         */
        public function get_cache_timeout() {
                /** @var $runtimeCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */
-               $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+               $runtimeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
                $cachedCacheLifetimeIdentifier = 'core-tslib_fe-get_cache_timeout';
                $cachedCacheLifetime = $runtimeCache->get($cachedCacheLifetimeIdentifier);
                if ($cachedCacheLifetime === FALSE) {
@@ -4877,7 +4877,7 @@ if (version == "n3") {
        protected function getSysDomainCache() {
                $entryIdentifier = 'core-database-sys_domain-complete';
                /** @var $runtimeCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */
-               $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+               $runtimeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
 
                $sysDomainData = array();
                if ($runtimeCache->has($entryIdentifier)) {
index bd89657..a81a1ff 100644 (file)
@@ -811,12 +811,10 @@ class PageRepository {
         */
        static public function getHash($hash, $expTime = 0) {
                $hashContent = NULL;
-               if (is_object($GLOBALS['typo3CacheManager'])) {
-                       $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-                       $cacheEntry = $contentHashCache->get($hash);
-                       if ($cacheEntry) {
-                               $hashContent = $cacheEntry;
-                       }
+               $contentHashCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
+               $cacheEntry = $contentHashCache->get($hash);
+               if ($cacheEntry) {
+                       $hashContent = $cacheEntry;
                }
                return $hashContent;
        }
@@ -835,9 +833,7 @@ class PageRepository {
         * @see tslib_TStemplate::start(), getHash()
         */
        static public function storeHash($hash, $data, $ident, $lifetime = 0) {
-               if (is_object($GLOBALS['typo3CacheManager'])) {
-                       $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), (int)$lifetime);
-               }
+               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), (int)$lifetime);
        }
 
        /**
index 7703b2b..3435d1e 100644 (file)
@@ -990,7 +990,7 @@ class IndexedPagesController extends \TYPO3\CMS\Backend\Module\AbstractFunctionM
                                                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                                        $idList[] = (int)$row['page_id'];
                                                }
-                                               $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+                                               $pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
                                                foreach ($idList as $pageId) {
                                                        $pageCache->flushByTag('pageId_' . $pageId);
                                                }
index 186e79f..9160970 100644 (file)
@@ -431,7 +431,7 @@ class AbstractController {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['options'] = array();
 
                /** @var $cacheManager \TYPO3\CMS\Core\Cache\CacheManager */
-               $cacheManager = $GLOBALS['typo3CacheManager'];
+               $cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
                $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
        }
 
index c0b8c3e..ee51478 100644 (file)
@@ -183,7 +183,7 @@ class DatabaseConnect extends AbstractStepAction {
                                        ->disableCoreAndClassesCache();
                                if ($this->isDbalEnabled()) {
                                        require(ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php');
-                                       $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                                }
                                if (!$this->isConnectSuccessful()) {
                                        /** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
index fe04a1d..3dcbc48 100644 (file)
@@ -67,7 +67,7 @@ class CachingFrameworkDatabaseSchemaService {
                        'groups' => array('system')
                );
                /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
-               $cacheManager = $GLOBALS['typo3CacheManager'];
+               $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
                $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
                $cacheSqlString = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
                $sqlString = str_replace($extbaseObjectFakeName, 'extbase_object', $cacheSqlString);
index cc12e0c..ff7245c 100644 (file)
@@ -82,7 +82,7 @@ class ClearCacheService {
                        ->initializeTypo3DbGlobal()
                        ->loadExtensionTables(FALSE);
 
-               // $GLOBALS['typo3CacheManager'] is already instantiated in the install tool
+               // The cache manager is already instantiated in the install tool
                // with some hacked settings to disable caching of extbase and fluid.
                // We want a "fresh" object here to operate on a different cache setup.
                // cacheManager implements SingletonInterface, so the only way to get a "fresh"
index aabbcbe..dd34ca5 100644 (file)
@@ -49,6 +49,6 @@ class StandaloneView extends \TYPO3\CMS\Fluid\View\StandaloneView {
                $controllerContext->setUriBuilder($uriBuilder);
                $this->setControllerContext($controllerContext);
                $this->templateCompiler = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler');
-               $this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+               $this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
        }
 }
index adac2f8..86c44b0 100644 (file)
@@ -57,7 +57,7 @@ class CachingFrameworkGarbageCollectionTask extends \TYPO3\CMS\Scheduler\Task\Ab
                                // The cache backend used for this cache
                                $usedCacheBackend = $cacheConfiguration['backend'];
                                if (in_array($usedCacheBackend, $this->selectedBackends)) {
-                                       $GLOBALS['typo3CacheManager']->getCache($cacheName)->collectGarbage();
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache($cacheName)->collectGarbage();
                                }
                        }
                }
index 08923c6..c30c366 100644 (file)
@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case
@@ -32,14 +33,35 @@ namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
 class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
+        * @var array
+        */
+       protected $singletonInstances = array();
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+       }
+
+       /**
+        * Reset singleton instances
+        */
+       public function tearDown() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+               parent::tearDown();
+       }
+
+       /**
         * @test
         */
        public function executeCallsCollectGarbageOfConfiguredBackend() {
                $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', array(), array(), '', FALSE);
                $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
                $cache->expects($this->atLeastOnce())->method('collectGarbage');
-               $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-               $GLOBALS['typo3CacheManager']->registerCache($cache);
+               $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
+               $mockCacheManager->registerCache($cache);
+               GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
                        'cache' => array(
                                'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
@@ -58,8 +80,9 @@ class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTe
                $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', array(), array(), '', FALSE);
                $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
                $cache->expects($this->never())->method('collectGarbage');
-               $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-               $GLOBALS['typo3CacheManager']->registerCache($cache);
+               $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
+               $mockCacheManager->registerCache($cache);
+               GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
                        'cache' => array(
                                'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
index 1582fee..92e77cc 100644 (file)
@@ -142,7 +142,7 @@ class DataHandlerHook {
         * @return void
         */
        protected function flushWorkspaceCacheEntriesByWorkspaceId($workspaceId) {
-               $workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
+               $workspacesCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('workspaces_cache');
                $workspacesCache->flushByTag($workspaceId);
                $workspacesCache->flushByTag(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
        }
index 774510b..aeca0ab 100644 (file)
@@ -247,7 +247,7 @@ class GridDataService {
         * @return void
         */
        protected function initializeWorkspacesCachingFramework() {
-               $this->workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
+               $this->workspacesCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('workspaces_cache');
        }
 
        /**