PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.5.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.5.0
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/composer/ClassLoader.php +83 -17 3.0.63.5.0 View file →
@@ -36,13 +36,15 @@
36 36 * This class is loosely based on the Symfony UniversalClassLoader.
37 37 *
38 38 * @author Fabien Potencier <fabien@symfony.com>
39 39 * @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/
40 + * @see https://www.php-fig.org/psr/psr-0/
41 + * @see https://www.php-fig.org/psr/psr-4/
42 42 */
43 43 class ClassLoader
44 44 {
45 + private $vendorDir;
46 +
45 47 // PSR-4
46 48 private $prefixLengthsPsr4 = array();
47 49 private $prefixDirsPsr4 = array();
48 50 private $fallbackDirsPsr4 = array();
@@ -52,15 +54,23 @@
52 54 private $fallbackDirsPsr0 = array();
53 55
54 56 private $useIncludePath = false;
55 57 private $classMap = array();
58 + private $classMapAuthoritative = false;
59 + private $missingClasses = array();
60 + private $apcuPrefix;
56 61
57 - private $classMapAuthoritative = false;
62 + private static $registeredLoaders = array();
58 63
64 + public function __construct($vendorDir = null)
65 + {
66 + $this->vendorDir = $vendorDir;
67 + }
68 +
59 69 public function getPrefixes()
60 70 {
61 71 if (!empty($this->prefixesPsr0)) {
62 - return call_user_func_array('array_merge', $this->prefixesPsr0);
72 + return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
63 73 }
64 74
65 75 return array();
66 76 }
@@ -271,8 +281,28 @@
271 281 return $this->classMapAuthoritative;
272 282 }
273 283
274 284 /**
285 + * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
286 + *
287 + * @param string|null $apcuPrefix
288 + */
289 + public function setApcuPrefix($apcuPrefix)
290 + {
291 + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
292 + }
293 +
294 + /**
295 + * The APCu prefix in use, or null if APCu caching is not enabled.
296 + *
297 + * @return string|null
298 + */
299 + public function getApcuPrefix()
300 + {
301 + return $this->apcuPrefix;
302 + }
303 +
304 + /**
275 305 * Registers this instance as an autoloader.
276 306 *
277 307 * @param bool $prepend Whether to prepend the autoloader or not
278 308 */
@@ -278,8 +308,19 @@
278 308 */
279 309 public function register($prepend = false)
280 310 {
281 311 spl_autoload_register(array($this, 'loadClass'), true, $prepend);
312 +
313 + if (null === $this->vendorDir) {
314 + return;
315 + }
316 +
317 + if ($prepend) {
318 + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
319 + } else {
320 + unset(self::$registeredLoaders[$this->vendorDir]);
321 + self::$registeredLoaders[$this->vendorDir] = $this;
322 + }
282 323 }
283 324
284 325 /**
285 326 * Unregisters this instance as an autoloader.
@@ -286,8 +327,12 @@
286 327 */
287 328 public function unregister()
288 329 {
289 330 spl_autoload_unregister(array($this, 'loadClass'));
331 +
332 + if (null !== $this->vendorDir) {
333 + unset(self::$registeredLoaders[$this->vendorDir]);
334 + }
290 335 }
291 336
292 337 /**
293 338 * Loads the given class or interface.
@@ -312,36 +357,51 @@
312 357 * @return string|false The path if found, false otherwise
313 358 */
314 359 public function findFile($class)
315 360 {
316 - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
317 - if ('\\' == $class[0]) {
318 - $class = substr($class, 1);
319 - }
320 -
321 361 // class map lookup
322 362 if (isset($this->classMap[$class])) {
323 363 return $this->classMap[$class];
324 364 }
325 - if ($this->classMapAuthoritative) {
365 + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
326 366 return false;
327 367 }
368 + if (null !== $this->apcuPrefix) {
369 + $file = apcu_fetch($this->apcuPrefix.$class, $hit);
370 + if ($hit) {
371 + return $file;
372 + }
373 + }
328 374
329 375 $file = $this->findFileWithExtension($class, '.php');
330 376
331 377 // Search for Hack files if we are running on HHVM
332 - if ($file === null && defined('HHVM_VERSION')) {
378 + if (false === $file && defined('HHVM_VERSION')) {
333 379 $file = $this->findFileWithExtension($class, '.hh');
334 380 }
335 381
336 - if ($file === null) {
382 + if (null !== $this->apcuPrefix) {
383 + apcu_add($this->apcuPrefix.$class, $file);
384 + }
385 +
386 + if (false === $file) {
337 387 // Remember that this class does not exist.
338 - return $this->classMap[$class] = false;
388 + $this->missingClasses[$class] = true;
339 389 }
340 390
341 391 return $file;
342 392 }
343 393
394 + /**
395 + * Returns the currently registered loaders indexed by their corresponding vendor directories.
396 + *
397 + * @return self[]
398 + */
399 + public static function getRegisteredLoaders()
400 + {
401 + return self::$registeredLoaders;
402 + }
403 +
344 404 private function findFileWithExtension($class, $ext)
345 405 {
346 406 // PSR-4 lookup
347 407 $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
@@ -347,12 +407,16 @@
347 407 $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
348 408
349 409 $first = $class[0];
350 410 if (isset($this->prefixLengthsPsr4[$first])) {
351 - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
352 - if (0 === strpos($class, $prefix)) {
353 - foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
354 - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
411 + $subPath = $class;
412 + while (false !== $lastPos = strrpos($subPath, '\\')) {
413 + $subPath = substr($subPath, 0, $lastPos);
414 + $search = $subPath . '\\';
415 + if (isset($this->prefixDirsPsr4[$search])) {
416 + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
417 + foreach ($this->prefixDirsPsr4[$search] as $dir) {
418 + if (file_exists($file = $dir . $pathEnd)) {
355 419 return $file;
356 420 }
357 421 }
358 422 }
@@ -398,8 +462,10 @@
398 462 // PSR-0 include paths.
399 463 if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
400 464 return $file;
401 465 }
466 +
467 + return false;
402 468 }
403 469 }
404 470
405 471 /**