annotate vendor/nikic/php-parser/lib/PhpParser/Autoloader.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace PhpParser;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * @codeCoverageIgnore
Chris@0 7 */
Chris@0 8 class Autoloader
Chris@0 9 {
Chris@0 10 /** @var bool Whether the autoloader has been registered. */
Chris@0 11 private static $registered = false;
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Registers PhpParser\Autoloader as an SPL autoloader.
Chris@0 15 *
Chris@0 16 * @param bool $prepend Whether to prepend the autoloader instead of appending
Chris@0 17 */
Chris@0 18 static public function register($prepend = false) {
Chris@0 19 if (self::$registered === true) {
Chris@0 20 return;
Chris@0 21 }
Chris@0 22
Chris@0 23 spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
Chris@0 24 self::$registered = true;
Chris@0 25 }
Chris@0 26
Chris@0 27 /**
Chris@0 28 * Handles autoloading of classes.
Chris@0 29 *
Chris@0 30 * @param string $class A class name.
Chris@0 31 */
Chris@0 32 static public function autoload($class) {
Chris@0 33 if (0 === strpos($class, 'PhpParser\\')) {
Chris@0 34 $fileName = __DIR__ . strtr(substr($class, 9), '\\', '/') . '.php';
Chris@0 35 if (file_exists($fileName)) {
Chris@0 36 require $fileName;
Chris@0 37 }
Chris@0 38 }
Chris@0 39 }
Chris@0 40 }