809a06ed8dd7a88a23417a75508e0cbf599a511b
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Autoloader.php
1 <?php
2
3 namespace PhpParser;
4
5 /**
6  * @codeCoverageIgnore
7  */
8 class Autoloader
9 {
10     /** @var bool Whether the autoloader has been registered. */
11     private static $registered = false;
12
13     /**
14      * Registers PhpParser\Autoloader as an SPL autoloader.
15      *
16      * @param bool $prepend Whether to prepend the autoloader instead of appending
17      */
18     static public function register($prepend = false) {
19         if (self::$registered === true) {
20             return;
21         }
22
23         spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
24         self::$registered = true;
25     }
26
27     /**
28      * Handles autoloading of classes.
29      *
30      * @param string $class A class name.
31      */
32     static public function autoload($class) {
33         if (0 === strpos($class, 'PhpParser\\')) {
34             $fileName = __DIR__ . strtr(substr($class, 9), '\\', '/') . '.php';
35             if (file_exists($fileName)) {
36                 require $fileName;
37             }
38         }
39     }
40 }