[CLEANUP] Move "finalClassNameCache" from GeneralUtility to ClassLoader 34/36234/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sat, 24 Jan 2015 15:05:50 +0000 (16:05 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 25 Jan 2015 17:15:13 +0000 (18:15 +0100)
Resolves: #56325
Releases: master
Change-Id: If17d756884e3749757e3e209f776b6665117fa5f
Reviewed-on: http://review.typo3.org/36234
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Core/ClassLoader.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 9a6f54a..a1baef0 100644 (file)
@@ -72,6 +72,13 @@ class ClassLoader {
         */
        protected $runtimeClassLoadingInformationCache = array();
 
         */
        protected $runtimeClassLoadingInformationCache = array();
 
+       /**
+        * Cache for makeInstance with given class name and final class names to reduce number of self::getClassName() calls
+        *
+        * @var array Given class name => final class name
+        */
+       static protected $finalClassNameCache = array();
+
        /**
         * A list of namespaces this class loader is definitely responsible for
         *
        /**
         * A list of namespaces this class loader is definitely responsible for
         *
@@ -707,6 +714,29 @@ class ClassLoader {
                return static::$staticAliasMap->getAliasesForClassName($className);
        }
 
                return static::$staticAliasMap->getAliasesForClassName($className);
        }
 
+       /**
+        * Add final class name to cache
+        *
+        * @param string $className
+        * @param string $finalClassName
+        */
+       static public function addFinalClassNameToCache($className, $finalClassName) {
+               static::$finalClassNameCache[$className] = $finalClassName;
+       }
+
+       /**
+        * Get final class name from cache
+        *
+        * @param string $className
+        * @return string|NULL
+        */
+       static public function getFinalClassNameFromCache($className) {
+               if (isset(static::$finalClassNameCache[$className])) {
+                       return static::$finalClassNameCache[$className];
+               }
+               return NULL;
+       }
+
        /**
         * Acquires a lock for the cache if we didn't already lock before.
         *
        /**
         * Acquires a lock for the cache if we didn't already lock before.
         *
index 4cb6a52..4ff5d37 100755 (executable)
@@ -68,13 +68,6 @@ class GeneralUtility {
         */
        static protected $nonSingletonInstances = array();
 
         */
        static protected $nonSingletonInstances = array();
 
-       /**
-        * Cache for makeInstance with given class name and final class names to reduce number of self::getClassName() calls
-        *
-        * @var array Given class name => final class name
-        */
-       static protected $finalClassNameCache = array();
-
        /**
         * The application context
         *
        /**
         * The application context
         *
@@ -4348,11 +4341,10 @@ Connection: close
                if ($className[0] === '\\') {
                        throw new \InvalidArgumentException('$className must not start with a backslash.', 1420281366);
                }
                if ($className[0] === '\\') {
                        throw new \InvalidArgumentException('$className must not start with a backslash.', 1420281366);
                }
-               if (isset(static::$finalClassNameCache[$className])) {
-                       $finalClassName = static::$finalClassNameCache[$className];
-               } else {
+               $finalClassName = ClassLoader::getFinalClassNameFromCache($className);
+               if ($finalClassName === NULL) {
                        $finalClassName = self::getClassName($className);
                        $finalClassName = self::getClassName($className);
-                       static::$finalClassNameCache[$className] = $finalClassName;
+                       ClassLoader::addFinalClassNameToCache($className, $finalClassName);
                }
                // Return singleton instance if it is already registered
                if (isset(self::$singletonInstances[$finalClassName])) {
                }
                // Return singleton instance if it is already registered
                if (isset(self::$singletonInstances[$finalClassName])) {