1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-03 09:47:59 +01:00
PHP-Parser/lib/PhpParser/Autoloader.php

41 lines
992 B
PHP
Raw Normal View History

<?php
namespace PhpParser;
/**
* @codeCoverageIgnore
*/
class Autoloader
{
2015-03-22 15:33:18 +01:00
/** @var bool Whether the autoloader has been registered. */
private static $registered = false;
/**
2014-02-12 14:06:32 +01:00
* Registers PhpParser\Autoloader as an SPL autoloader.
*
* @param bool $prepend Whether to prepend the autoloader instead of appending
*/
static public function register($prepend = false) {
2015-03-22 15:33:18 +01:00
if (self::$registered === true) {
return;
}
2015-03-22 15:33:18 +01:00
2014-02-12 14:06:32 +01:00
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
2015-03-22 15:33:18 +01:00
self::$registered = true;
}
/**
2014-02-12 14:06:32 +01:00
* Handles autoloading of classes.
*
* @param string $class A class name.
*/
static public function autoload($class) {
if (0 === strpos($class, 'PhpParser\\')) {
$fileName = dirname(__DIR__) . '/' . strtr($class, '\\', '/') . '.php';
if (file_exists($fileName)) {
require $fileName;
}
}
}
}