PluginProbe
CSS & JavaScript Toolbox / 8.3.2
CSS & JavaScript Toolbox v8.3.2
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | vendor/composer/ClassLoader.php +16 -74 118.3.2 View file →
@@ -12,10 +12,12 @@
12 12
13 13 namespace Composer\Autoload;
14 14
15 15 /**
16 - * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
16 + * ClassLoader implements a PSR-0 class loader
17 17 *
18 + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
19 + *
18 20 * $loader = new \Composer\Autoload\ClassLoader();
19 21 *
20 22 * // register classes with namespaces
21 23 * $loader->add('Symfony\Component', __DIR__.'/component');
@@ -36,10 +38,8 @@
36 38 * This class is loosely based on the Symfony UniversalClassLoader.
37 39 *
38 40 * @author Fabien Potencier <fabien@symfony.com>
39 41 * @author Jordi Boggiano <j.boggiano@seld.be>
40 - * @see http://www.php-fig.org/psr/psr-0/
41 - * @see http://www.php-fig.org/psr/psr-4/
42 42 */
43 43 class ClassLoader
44 44 {
45 45 // PSR-4
@@ -52,11 +52,8 @@
52 52 private $fallbackDirsPsr0 = array();
53 53
54 54 private $useIncludePath = false;
55 55 private $classMap = array();
56 - private $classMapAuthoritative = false;
57 - private $missingClasses = array();
58 - private $apcuPrefix;
59 56
60 57 public function getPrefixes()
61 58 {
62 59 if (!empty($this->prefixesPsr0)) {
@@ -147,9 +144,9 @@
147 144 * Registers a set of PSR-4 directories for a given namespace, either
148 145 * appending or prepending to the ones previously set for this namespace.
149 146 *
150 147 * @param string $prefix The prefix/namespace, with trailing '\\'
151 - * @param array|string $paths The PSR-4 base directories
148 + * @param array|string $paths The PSR-0 base directories
152 149 * @param bool $prepend Whether to prepend the directories
153 150 *
154 151 * @throws \InvalidArgumentException
155 152 */
@@ -251,49 +248,8 @@
251 248 return $this->useIncludePath;
252 249 }
253 250
254 251 /**
255 - * Turns off searching the prefix and fallback directories for classes
256 - * that have not been registered with the class map.
257 - *
258 - * @param bool $classMapAuthoritative
259 - */
260 - public function setClassMapAuthoritative($classMapAuthoritative)
261 - {
262 - $this->classMapAuthoritative = $classMapAuthoritative;
263 - }
264 -
265 - /**
266 - * Should class lookup fail if not found in the current class map?
267 - *
268 - * @return bool
269 - */
270 - public function isClassMapAuthoritative()
271 - {
272 - return $this->classMapAuthoritative;
273 - }
274 -
275 - /**
276 - * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277 - *
278 - * @param string|null $apcuPrefix
279 - */
280 - public function setApcuPrefix($apcuPrefix)
281 - {
282 - $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
283 - }
284 -
285 - /**
286 - * The APCu prefix in use, or null if APCu caching is not enabled.
287 - *
288 - * @return string|null
289 - */
290 - public function getApcuPrefix()
291 - {
292 - return $this->apcuPrefix;
293 - }
294 -
295 - /**
296 252 * Registers this instance as an autoloader.
297 253 *
298 254 * @param bool $prepend Whether to prepend the autoloader or not
299 255 */
@@ -333,36 +289,28 @@
333 289 * @return string|false The path if found, false otherwise
334 290 */
335 291 public function findFile($class)
336 292 {
293 + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
294 + if ('\\' == $class[0]) {
295 + $class = substr($class, 1);
296 + }
297 +
337 298 // class map lookup
338 299 if (isset($this->classMap[$class])) {
339 300 return $this->classMap[$class];
340 301 }
341 - if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342 - return false;
343 - }
344 - if (null !== $this->apcuPrefix) {
345 - $file = apcu_fetch($this->apcuPrefix.$class, $hit);
346 - if ($hit) {
347 - return $file;
348 - }
349 - }
350 302
351 303 $file = $this->findFileWithExtension($class, '.php');
352 304
353 305 // Search for Hack files if we are running on HHVM
354 - if (false === $file && defined('HHVM_VERSION')) {
306 + if ($file === null && defined('HHVM_VERSION')) {
355 307 $file = $this->findFileWithExtension($class, '.hh');
356 308 }
357 309
358 - if (null !== $this->apcuPrefix) {
359 - apcu_add($this->apcuPrefix.$class, $file);
360 - }
361 -
362 - if (false === $file) {
310 + if ($file === null) {
363 311 // Remember that this class does not exist.
364 - $this->missingClasses[$class] = true;
312 + return $this->classMap[$class] = false;
365 313 }
366 314
367 315 return $file;
368 316 }
@@ -373,16 +321,12 @@
373 321 $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374 322
375 323 $first = $class[0];
376 324 if (isset($this->prefixLengthsPsr4[$first])) {
377 - $subPath = $class;
378 - while (false !== $lastPos = strrpos($subPath, '\\')) {
379 - $subPath = substr($subPath, 0, $lastPos);
380 - $search = $subPath . '\\';
381 - if (isset($this->prefixDirsPsr4[$search])) {
382 - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383 - foreach ($this->prefixDirsPsr4[$search] as $dir) {
384 - if (file_exists($file = $dir . $pathEnd)) {
325 + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
326 + if (0 === strpos($class, $prefix)) {
327 + foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
328 + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
385 329 return $file;
386 330 }
387 331 }
388 332 }
@@ -428,10 +372,8 @@
428 372 // PSR-0 include paths.
429 373 if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430 374 return $file;
431 375 }
432 -
433 - return false;
434 376 }
435 377 }
436 378
437 379 /**