1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Remove Autoloader class

This commit is contained in:
Nikita Popov 2018-01-25 23:13:53 +01:00
parent c2d3ecad35
commit 6a273c9fbd
6 changed files with 7 additions and 67 deletions

View File

@ -11,6 +11,10 @@ Version 4.0.0-dev
* In formatting-preserving pretty printer:
* Improved formatting of elements inserted into multi-line arrays.
### Removed
* The `Autoloader` class has been removed. It is not required to use the Composer autoloader.
Version 4.0.0-alpha3 (2017-12-26)
---------------------------------

View File

@ -73,4 +73,5 @@ Because HHVM does not support PHP 7, HHVM is no longer supported.
* The XML serializer has been removed. As such, the classes `Serializer\XML`, and
`Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist.
* The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`.
However, this is an internal class and should not be used directly.
However, this is an internal class and should not be used directly.
* The `Autoloader` class has been removed in favor of relying on the Composer autoloader.

View File

@ -1,40 +0,0 @@
<?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;
}
}
}
}

View File

@ -1,6 +0,0 @@
<?php declare(strict_types=1);
if (!class_exists(PhpParser\Autoloader::class)) {
require __DIR__ . '/PhpParser/Autoloader.php';
}
PhpParser\Autoloader::register();

View File

@ -1,18 +0,0 @@
<?php declare(strict_types=1);
namespace PhpParser;
/* The autoloader is already active at this point, so we only check effects here. */
use PHPUnit\Framework\TestCase;
class AutoloaderTest extends TestCase
{
public function testClassExists() {
$this->assertTrue(class_exists(NodeVisitorAbstract::class));
$this->assertFalse(class_exists('PHPParser_NodeVisitor_NameResolver'));
$this->assertFalse(class_exists('PhpParser\FooBar'));
$this->assertFalse(class_exists('PHPParser_FooBar'));
}
}

View File

@ -110,8 +110,7 @@ switch ($testType) {
showHelp('Test type must be one of: PHP5, PHP7 or Symfony');
}
require_once __DIR__ . '/../lib/PhpParser/Autoloader.php';
PhpParser\Autoloader::register();
require_once __DIR__ . '/../vendor/autoload.php';
$lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => [
'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos',