1
0
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:
nikic 2011-06-05 18:47:52 +02:00
parent 620525a5da
commit 83a2077f0e
4 changed files with 43 additions and 7 deletions

View File

@ -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
----------------------

View 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;
}
}
}

View 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;

View File

@ -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;