[TASK] Class Loader optimisation 36/26836/5
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 15 Jan 2014 14:05:30 +0000 (15:05 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Fri, 14 Feb 2014 15:33:27 +0000 (16:33 +0100)
* Skip cache->has() calls
* Remove class alias registration on object instantiation

Resolves: #55037
Releases: 6.2
Change-Id: Ia9f8523a9d710b2703c3ee2caf2f1fa9ae6e76e9
Reviewed-on: https://review.typo3.org/26836
Reviewed-by: Markus Klein
Reviewed-by: Thomas Maroschik
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Core/ClassAliasMap.php
typo3/sysext/core/Classes/Core/ClassLoader.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 4b6026e..ab1bfcf 100644 (file)
@@ -174,7 +174,7 @@ class ClassAliasMap implements \TYPO3\CMS\Core\SingletonInterface {
                }
                $this->aliasToClassNameMapping[$lowercasedAliasClassName] = $originalClassName;
                $this->classNameToAliasMapping[strtolower($originalClassName)][$lowercasedAliasClassName] = $aliasClassName;
-               return (\class_exists($aliasClassName, FALSE) || \interface_exists($aliasClassName, FALSE)) ? TRUE : class_alias($originalClassName, $aliasClassName);
+               return (class_exists($aliasClassName, FALSE) || interface_exists($aliasClassName, FALSE)) ? TRUE : class_alias($originalClassName, $aliasClassName);
        }
 
        /**
index f1d0062..5cc2256 100644 (file)
@@ -154,8 +154,9 @@ class ClassLoader {
 
                $cacheEntryIdentifier = strtolower(str_replace('\\', '_', $className));
                try {
-                       if ($this->classesCache->has($cacheEntryIdentifier)) {
-                               $classLoadingInformation = explode("\xff", $this->classesCache->get($cacheEntryIdentifier));
+                       $rawClassLoadingInformation = $this->classesCache->get($cacheEntryIdentifier);
+                       if ($rawClassLoadingInformation !== FALSE) {
+                               $classLoadingInformation = explode("\xff", $rawClassLoadingInformation);
                        } else {
                                $classLoadingInformation = $this->buildClassLoadingInformation($className);
                                if ($classLoadingInformation !== NULL) {
@@ -172,14 +173,11 @@ class ClassLoader {
                //   1 => original class name
                //   2 and following => alias class names
                // )
-
                $loadingSuccessful = FALSE;
                if ($classLoadingInformation !== NULL) {
-                       if (class_exists($classLoadingInformation[1], FALSE)) {
-                               $loadingSuccessful = TRUE;
-                       } else {
-                               $loadingSuccessful = (boolean)require_once $classLoadingInformation[0];
-                       }
+                       // The call to class_exists fixes a rare case when early instances need to be aliased
+                       // but PHP fails to recognize the real path of the class. See #55904
+                       $loadingSuccessful = class_exists($classLoadingInformation[1], FALSE) || (bool)require_once $classLoadingInformation[0];
                }
                if ($loadingSuccessful && count($classLoadingInformation) > 2) {
                        $originalClassName = $classLoadingInformation[1];
@@ -269,7 +267,7 @@ class ClassLoader {
                                        // The namespace part is substituted.
                                        $classPathAndFilename = '/' . str_replace('\\', '/', ltrim(substr($className, $packageData['namespaceLength']), '\\')) . '.php';
                                } else {
-                                       // make the classname PSR-0 compliant by replacing underscores only in the classname not in the namespace
+                                       // Make the classname PSR-0 compliant by replacing underscores only in the classname not in the namespace
                                        $classPathAndFilename  = '';
                                        $lastNamespacePosition = strrpos($className, '\\');
                                        if ($lastNamespacePosition !== FALSE) {
@@ -337,9 +335,7 @@ class ClassLoader {
                        } else {
                                $classesPath = $this->packageClassesPaths[$extensionKey];
                        }
-                       // Naming convention is to capitalize each part of the path
-                       $classNameWithoutVendorAndProduct = ucwords(strtr($classNameWithoutVendorAndProduct, $delimiter, LF));
-                       $classFilePath = $classesPath . strtr($classNameWithoutVendorAndProduct, LF, '/') . '.php';
+                       $classFilePath = $classesPath . strtr($classNameWithoutVendorAndProduct, $delimiter, '/') . '.php';
                        if (@file_exists($classFilePath)) {
                                return array($classFilePath, $className);
                        }
@@ -358,7 +354,7 @@ class ClassLoader {
        }
 
        /**
-        * Get cache entry identifier
+        * Get cache entry identifier for the package namespaces cache
         *
         * @return string|null identifier
         */
@@ -371,7 +367,7 @@ class ClassLoader {
        /**
         * Set cache identifier
         *
-        * @param string $cacheIdentifier Cache identifier
+        * @param string $cacheIdentifier Cache identifier for package namespaces cache
         * @return ClassLoader
         */
        public function setCacheIdentifier($cacheIdentifier) {
@@ -455,8 +451,12 @@ class ClassLoader {
         */
        protected function loadPackageNamespacesFromCache() {
                $cacheEntryIdentifier = $this->getCacheEntryIdentifier();
-               if ($cacheEntryIdentifier !== NULL && $this->coreCache->has($cacheEntryIdentifier)) {
-                       list($packageNamespaces, $packageClassesPaths) = $this->coreCache->requireOnce($cacheEntryIdentifier);
+               if ($cacheEntryIdentifier === NULL) {
+                       return FALSE;
+               }
+               $packageData = $this->coreCache->requireOnce($cacheEntryIdentifier);
+               if ($packageData !== FALSE) {
+                       list($packageNamespaces, $packageClassesPaths) = $packageData;
                        if (is_array($packageNamespaces) && is_array($packageClassesPaths)) {
                                $this->packageNamespaces = $packageNamespaces;
                                $this->packageClassesPaths = $packageClassesPaths;
index 4150beb..0ee56bc 100644 (file)
@@ -4265,11 +4265,6 @@ Connection: close
                }
                // Create new instance and call constructor with parameters
                $instance = static::instantiateClass($finalClassName, func_get_args());
-               // Create alias if not present
-               $alias = \TYPO3\CMS\Core\Core\ClassLoader::getAliasForClassName($finalClassName);
-               if ($finalClassName !== $alias && !class_exists($alias, FALSE)) {
-                       class_alias($finalClassName, $alias);
-               }
                // Register new singleton instance
                if ($instance instanceof \TYPO3\CMS\Core\SingletonInterface) {
                        self::$singletonInstances[$finalClassName] = $instance;