1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-11 00:49:40 +01:00
PHP-Parser/lib/PhpParser/Autoloader.php
2015-05-02 22:21:12 +02:00

41 lines
992 B
PHP

<?php
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
*/
static public function register($prepend = false) {
if (self::$registered === true) {
return;
}
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
self::$registered = true;
}
/**
* 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;
}
}
}
}