mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
bf7d811cda
* [PSR-2] Visibility before static * [PSR-2] Declare method Visibility
41 lines
1020 B
PHP
41 lines
1020 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace PhpParser;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class Autoloader
|
|
{
|
|
/** @var bool Whether the autoloader has been registered. */
|
|
private static $registered = false;
|
|
|
|
/**
|
|
* Registers PhpParser\Autoloader as an SPL autoloader.
|
|
*
|
|
* @param bool $prepend Whether to prepend the autoloader instead of appending
|
|
*/
|
|
public static function register(bool $prepend = false) {
|
|
if (self::$registered === true) {
|
|
return;
|
|
}
|
|
|
|
spl_autoload_register([__CLASS__, 'autoload'], true, $prepend);
|
|
self::$registered = true;
|
|
}
|
|
|
|
/**
|
|
* Handles autoloading of classes.
|
|
*
|
|
* @param string $class A class name.
|
|
*/
|
|
public static function autoload(string $class) {
|
|
if (0 === strpos($class, 'PhpParser\\')) {
|
|
$fileName = __DIR__ . strtr(substr($class, 9), '\\', '/') . '.php';
|
|
if (file_exists($fileName)) {
|
|
require $fileName;
|
|
}
|
|
}
|
|
}
|
|
}
|