From 15b2477643dcee80d2d91d2041744094a649ed8a Mon Sep 17 00:00:00 2001
From: Helmut Hummel <helmut.hummel@typo3.org>
Date: Mon, 10 Aug 2015 23:06:17 +0200
Subject: [PATCH] [TASK] Update to latest class alias loader version

Benefit from several class alias loader package improvements:

* Use alias map API of this package to resolve and add aliases
* Use new option to force initialization of the alias loader to greatly simplify our runtime code
  This option is only evaluated in non composer mode, which is good because we only need it then.
* Adapt to API change, that now the alias loader is never returned from autoload inclusion

Resolves: #68916
Releases: master
Change-Id: I1aec36634bbfc896c9506c8c846ddf86f78c1693
Reviewed-on: http://review.typo3.org/42492
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
---
 composer.json                                 |  3 ++
 composer.lock                                 | 12 +++----
 .../backend/Classes/Console/Application.php   |  2 +-
 .../backend/Classes/Http/Application.php      |  2 +-
 typo3/sysext/core/Classes/Core/Bootstrap.php  |  2 +-
 .../Classes/Core/ClassLoadingInformation.php  | 32 +++----------------
 .../frontend/Classes/Http/Application.php     |  2 +-
 .../install/Classes/Http/Application.php      |  2 +-
 8 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/composer.json b/composer.json
index e2447905cdf8..05f80d783180 100644
--- a/composer.json
+++ b/composer.json
@@ -57,6 +57,9 @@
 		"ext-zip": ""
 	},
 	"extra": {
+		"helhum/class-alias-loader": {
+			"always-add-alias-loader": true
+		},
 		"branch-alias": {
 			"dev-master": "7.x-dev"
 		}
diff --git a/composer.lock b/composer.lock
index 1c079fc23727..72d26e6b00e8 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "0f463179dd109b3ff4000ea49c17cec9",
+    "hash": "6baf4c6d3b67a0f30e2f1d9f6c84f446",
     "packages": [
         {
             "name": "doctrine/instantiator",
@@ -62,16 +62,16 @@
         },
         {
             "name": "helhum/class-alias-loader",
-            "version": "2.0.0",
+            "version": "2.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/helhum/class-alias-loader.git",
-                "reference": "28e9155b8ab3f2871f32899d4fa355fd14daba95"
+                "reference": "91ef94c5a0ab6883018c8125ed66c00e5704ff6a"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/helhum/class-alias-loader/zipball/28e9155b8ab3f2871f32899d4fa355fd14daba95",
-                "reference": "28e9155b8ab3f2871f32899d4fa355fd14daba95",
+                "url": "https://api.github.com/repos/helhum/class-alias-loader/zipball/91ef94c5a0ab6883018c8125ed66c00e5704ff6a",
+                "reference": "91ef94c5a0ab6883018c8125ed66c00e5704ff6a",
                 "shasum": ""
             },
             "require": {
@@ -113,7 +113,7 @@
                 "classloader",
                 "composer"
             ],
-            "time": "2015-08-06 22:03:20"
+            "time": "2015-08-10 20:58:34"
         },
         {
             "name": "pear/http_request2",
diff --git a/typo3/sysext/backend/Classes/Console/Application.php b/typo3/sysext/backend/Classes/Console/Application.php
index c86b4535ccd9..33b22102d4d8 100644
--- a/typo3/sysext/backend/Classes/Console/Application.php
+++ b/typo3/sysext/backend/Classes/Console/Application.php
@@ -44,7 +44,7 @@ class Application implements ApplicationInterface {
 	/**
 	 * Constructor setting up legacy constants and register available Request Handlers
 	 *
-	 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\ClassAliasLoader $classLoader an instance of the class loader
+	 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
 	 */
 	public function __construct($classLoader) {
 		$this->checkEnvironmentOrDie();
diff --git a/typo3/sysext/backend/Classes/Http/Application.php b/typo3/sysext/backend/Classes/Http/Application.php
index 3b77c66d24cc..b7e5d49b5e86 100644
--- a/typo3/sysext/backend/Classes/Http/Application.php
+++ b/typo3/sysext/backend/Classes/Http/Application.php
@@ -50,7 +50,7 @@ class Application implements ApplicationInterface {
 	/**
 	 * Constructor setting up legacy constant and register available Request Handlers
 	 *
-	 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\ClassAliasLoader $classLoader an instance of the class loader
+	 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
 	 */
 	public function __construct($classLoader) {
 		$this->defineLegacyConstants();
diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php
index 5eb1d54180d1..ef9047cdd4ba 100644
--- a/typo3/sysext/core/Classes/Core/Bootstrap.php
+++ b/typo3/sysext/core/Classes/Core/Bootstrap.php
@@ -192,7 +192,7 @@ class Bootstrap {
 	/**
 	 * Sets the class loader to the bootstrap
 	 *
-	 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\ClassAliasLoader $classLoader an instance of the class loader
+	 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
 	 * @return Bootstrap
 	 * @internal This is not a public API method, do not use in own extensions
 	 */
diff --git a/typo3/sysext/core/Classes/Core/ClassLoadingInformation.php b/typo3/sysext/core/Classes/Core/ClassLoadingInformation.php
index 9497304698f7..231407e1c01c 100644
--- a/typo3/sysext/core/Classes/Core/ClassLoadingInformation.php
+++ b/typo3/sysext/core/Classes/Core/ClassLoadingInformation.php
@@ -15,7 +15,7 @@ namespace TYPO3\CMS\Core\Core;
  */
 
 use Composer\Autoload\ClassLoader as ComposerClassLoader;
-use Helhum\ClassAliasLoader\ClassAliasLoader;
+use Helhum\ClassAliasLoader\ClassAliasMap;
 use TYPO3\CMS\Core\Package\PackageInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -90,7 +90,7 @@ class ClassLoadingInformation {
 		if (file_exists($dynamicClassAliasMapFile)) {
 			$classAliasMap = require $dynamicClassAliasMapFile;
 			if (is_array($classAliasMap) && !empty($classAliasMap['aliasToClassNameMapping']) && !empty($classAliasMap['classNameToAliasMapping'])) {
-				self::getClassAliasLoader($composerClassLoader)->addAliasMap($classAliasMap);
+				ClassAliasMap::addAliasMap($classAliasMap);
 			}
 		}
 
@@ -132,7 +132,7 @@ class ClassLoadingInformation {
 		}
 		$classAliasMap = $generator->buildClassAliasMapForPackage($package);
 		if (is_array($classAliasMap) && !empty($classAliasMap['aliasToClassNameMapping']) && !empty($classAliasMap['classNameToAliasMapping'])) {
-			self::getClassAliasLoader($composerClassLoader)->addAliasMap($classAliasMap);
+			ClassAliasMap::addAliasMap($classAliasMap);
 		}
 	}
 
@@ -154,11 +154,7 @@ class ClassLoadingInformation {
 	 * @return mixed
 	 */
 	static public function getClassNameForAlias($alias) {
-		$composerClassLoader = static::getClassLoader();
-		if (!is_callable(array($composerClassLoader, 'getClassNameForAlias'))) {
-			return $alias;
-		}
-		return $composerClassLoader->getClassNameForAlias($alias);
+		return ClassAliasMap::getClassNameForAlias($alias);
 	}
 
 	/**
@@ -177,29 +173,11 @@ class ClassLoadingInformation {
 	/**
 	 * Internal method calling the bootstrap to fetch the composer class loader
 	 *
-	 * @return ClassAliasLoader|ComposerClassLoader
+	 * @return ComposerClassLoader
 	 * @throws \TYPO3\CMS\Core\Exception
 	 */
 	static protected function getClassLoader() {
 		return Bootstrap::getInstance()->getEarlyInstance(ComposerClassLoader::class);
 	}
 
-	/**
-	 * Internal method calling the bootstrap to fetch the composer class loader
-	 *
-	 * @param ClassAliasLoader|ComposerClassLoader $composerClassLoader
-	 * @return ClassAliasLoader
-	 * @throws \TYPO3\CMS\Core\Exception
-	 */
-	static protected function getClassAliasLoader($composerClassLoader) {
-		if ($composerClassLoader instanceof ClassAliasLoader) {
-			return $composerClassLoader;
-		}
-		$aliasLoader = new ClassAliasLoader($composerClassLoader);
-		$aliasLoader->register(TRUE);
-		Bootstrap::getInstance()->setEarlyInstance(ComposerClassLoader::class, $aliasLoader);
-
-		return $aliasLoader;
-	}
-
 }
diff --git a/typo3/sysext/frontend/Classes/Http/Application.php b/typo3/sysext/frontend/Classes/Http/Application.php
index 43d29d4d0563..9800993b33d3 100644
--- a/typo3/sysext/frontend/Classes/Http/Application.php
+++ b/typo3/sysext/frontend/Classes/Http/Application.php
@@ -45,7 +45,7 @@ class Application implements ApplicationInterface {
 	/**
 	 * Constructor setting up legacy constant and register available Request Handlers
 	 *
-	 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\ClassAliasLoader $classLoader an instance of the class loader
+	 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
 	 */
 	public function __construct($classLoader) {
 		$this->defineLegacyConstants();
diff --git a/typo3/sysext/install/Classes/Http/Application.php b/typo3/sysext/install/Classes/Http/Application.php
index 929fe4c503cf..db6113aa1b71 100644
--- a/typo3/sysext/install/Classes/Http/Application.php
+++ b/typo3/sysext/install/Classes/Http/Application.php
@@ -43,7 +43,7 @@ class Application implements ApplicationInterface {
 	/**
 	 * Constructor setting up legacy constant and register available Request Handlers
 	 *
-	 * @param \Composer\Autoload\ClassLoader|\Helhum\ClassAliasLoader\ClassAliasLoader $classLoader an instance of the class loader
+	 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
 	 */
 	public function __construct($classLoader) {
 		$this->defineLegacyConstants();
-- 
GitLab