|
43 | 43 | class ClassLoader |
44 | 44 | { |
45 | 45 | // PSR-4 |
46 | | - private $firstCharsPsr4 = array(); |
47 | | - private $prefixLengthsPsr4 = array(); // For BC with legacy static maps |
| 46 | + private $prefixLengthsPsr4 = array(); |
48 | 47 | private $prefixDirsPsr4 = array(); |
49 | 48 | private $fallbackDirsPsr4 = array(); |
50 | 49 |
|
@@ -171,10 +170,11 @@ public function addPsr4($prefix, $paths, $prepend = false) |
171 | 170 | } |
172 | 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
173 | 172 | // Register directories for a new namespace. |
174 | | - if ('\\' !== substr($prefix, -1)) { |
| 173 | + $length = strlen($prefix); |
| 174 | + if ('\\' !== $prefix[$length - 1]) { |
175 | 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
176 | 176 | } |
177 | | - $this->firstCharsPsr4[$prefix[0]] = true; |
| 177 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
178 | 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; |
179 | 179 | } elseif ($prepend) { |
180 | 180 | // Prepend directories for an already registered namespace. |
@@ -221,10 +221,11 @@ public function setPsr4($prefix, $paths) |
221 | 221 | if (!$prefix) { |
222 | 222 | $this->fallbackDirsPsr4 = (array) $paths; |
223 | 223 | } else { |
224 | | - if ('\\' !== substr($prefix, -1)) { |
| 224 | + $length = strlen($prefix); |
| 225 | + if ('\\' !== $prefix[$length - 1]) { |
225 | 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); |
226 | 227 | } |
227 | | - $this->firstCharsPsr4[$prefix[0]] = true; |
| 228 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
228 | 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; |
229 | 230 | } |
230 | 231 | } |
@@ -372,7 +373,7 @@ private function findFileWithExtension($class, $ext) |
372 | 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
373 | 374 |
|
374 | 375 | $first = $class[0]; |
375 | | - if (isset($this->firstCharsPsr4[$first]) || isset($this->prefixLengthsPsr4[$first])) { |
| 376 | + if (isset($this->prefixLengthsPsr4[$first])) { |
376 | 377 | $subPath = $class; |
377 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
378 | 379 | $subPath = substr($subPath, 0, $lastPos); |
|
0 commit comments