From ce70e0e9dd63e4f3fcdd0eb2d960873d160a3a2f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Jan 2018 13:33:31 +0100 Subject: [PATCH] Fix BC of generated static map --- src/Composer/Autoload/AutoloadGenerator.php | 5 +---- src/Composer/Autoload/ClassLoader.php | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index dca6a7553..87b250617 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -785,10 +785,7 @@ HEADER; // BC handling when converting to a new ClassLoader if (isset($maps['prefixLengthsPsr4'])) { - $maps['firstCharsPsr4'] = array_map(function () { - return true; - }, $maps['prefixLengthsPsr4']); - unset($maps['prefixLengthsPsr4']); + $maps['firstCharsPsr4'] = array_map('is_array', $maps['prefixLengthsPsr4']); } foreach ($maps as $prop => $value) { diff --git a/src/Composer/Autoload/ClassLoader.php b/src/Composer/Autoload/ClassLoader.php index bebe83706..c6f6d2322 100644 --- a/src/Composer/Autoload/ClassLoader.php +++ b/src/Composer/Autoload/ClassLoader.php @@ -44,6 +44,7 @@ class ClassLoader { // PSR-4 private $firstCharsPsr4 = array(); + private $prefixLengthsPsr4 = array(); // For BC with legacy static maps private $prefixDirsPsr4 = array(); private $fallbackDirsPsr4 = array(); @@ -371,15 +372,15 @@ class ClassLoader $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; $first = $class[0]; - if (isset($this->firstCharsPsr4[$first])) { + if (isset($this->firstCharsPsr4[$first]) || isset($this->prefixLengthsPsr4[$first])) { $subPath = $class; while (false !== $lastPos = strrpos($subPath, '\\')) { $subPath = substr($subPath, 0, $lastPos); $search = $subPath.'\\'; if (isset($this->prefixDirsPsr4[$search])) { - $pathEnd = substr($logicalPathPsr4, $lastPos + 1); + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); foreach ($this->prefixDirsPsr4[$search] as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $pathEnd)) { + if (file_exists($file = $dir . $pathEnd)) { return $file; } }