1. Install
Reflect may be installed in several ways, choose your favorite.
Minimal Requirements
Before you install PHP Reflect, you will need an operating system with PHP 5.3.0 or later installed, and four loaded extensions: Reflection, tokenizer, pcre, SPL.
Using PEAR
As PHP-Parser 1.0 is not planned to be distributed as a PEAR package (read more), Reflect 2.0 will not be available on the PEAR Bartlett Channel.
Using Composer
Put a file named composer.json at the root of your project, with the content below:
{ "require": { "bartlett/php-reflect": "2.0.0" } }
And run the following command:
$ php composer.phar install
Using PHP Archive (phar)
wget http://bartlett.laurent-laville.org/get/phpreflect.phar chmod +x phpreflect.phar
2. Autoloaders
Reflect does not provides any native autoloader.
It’s up to you to choose what is be the best strategy :
-
If you have installed Reflect with Composer, it must have generated a
vendor/autoload.php
file you should used. -
If you use the phar version, you don’t need autoloader, except if you want to add some user components.
-
The basic PHP version requires an autoloader that can load classes that follow the PSR-0 class naming standard.
Here are a minimum example, if you used a forked copy of GitHub source.
<?php
$baseDir = dirname(__DIR__);
$vendorDir = $baseDir . '/vendor';
require_once $vendorDir . '/nikic/php-parser/lib/bootstrap.php';
require_once $vendorDir . '/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once $vendorDir . '/phpunit/php-timer/PHP/Timer.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony\\Component\\Finder' => $vendorDir . '/symfony/finder',
'Symfony\\Component\\EventDispatcher' => $vendorDir . '/symfony/event-dispatcher',
'Symfony\\Component\\Console' => $vendorDir . '/symfony/console',
'Symfony\\Component\\ClassLoader' => $vendorDir . '/symfony/class-loader',
'Bartlett\\Tests\\Reflect' => $baseDir . '/tests',
'Bartlett' => $baseDir . '/src',
));
$loader->register();
You are now ready to parse your first data source.