mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
Add Autoloader
This commit is contained in:
parent
620525a5da
commit
83a2077f0e
@ -15,6 +15,14 @@ This package currently bundles several components:
|
||||
* A `NodeDumper` to dump the nodes to a human readable string representation
|
||||
* A `PrettyPrinter` to translate the node tree back to PHP
|
||||
|
||||
Autoloader
|
||||
----------
|
||||
|
||||
In order to automatically include required files `PHPParser_Autoloader` can be used:
|
||||
|
||||
require_once 'path/to/phpparser/lib/PHPParser/Autoloader.php';
|
||||
PHPParser_Autoloader::register();
|
||||
|
||||
Parser and ParserDebug
|
||||
----------------------
|
||||
|
||||
|
30
lib/PHPParser/Autoloader.php
Normal file
30
lib/PHPParser/Autoloader.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Autoloader
|
||||
{
|
||||
/**
|
||||
* Registers PHPParser_Autoloader as an SPL autoloader.
|
||||
*/
|
||||
static public function register()
|
||||
{
|
||||
ini_set('unserialize_callback_func', 'spl_autoload_call');
|
||||
spl_autoload_register(array(new self, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles autoloading of classes.
|
||||
*
|
||||
* @param string $class A class name.
|
||||
*/
|
||||
static public function autoload($class)
|
||||
{
|
||||
if (0 !== strpos($class, 'PHPParser')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = dirname(dirname(__FILE__)) . '/' . strtr($class, '_', '/') . '.php';
|
||||
if (is_file($file)) {
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
$DIR = '../..';
|
||||
$DIR = '../../Symfony';
|
||||
|
||||
function __autoload($class) {
|
||||
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
|
||||
}
|
||||
require_once '../lib/PHPParser/Autoloader.php';
|
||||
PHPParser_Autoloader::register();
|
||||
|
||||
$parser = new PHPParser_Parser;
|
||||
$prettyPrinter = new PHPParser_PrettyPrinter_Zend;
|
||||
|
@ -12,9 +12,8 @@ a::$b()
|
||||
a::$b[c]()
|
||||
EXPRS;
|
||||
|
||||
function __autoload($class) {
|
||||
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
|
||||
}
|
||||
require_once '../lib/PHPParser/Autoloader.php';
|
||||
PHPParser_Autoloader::register();
|
||||
|
||||
$parser = new PHPParser_Parser;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user