Using cache feature
Version 3.2
<?php
require_once 'vendor/autoload.php';
use Bartlett\CompatInfo;
use Bartlett\Reflect\ProviderManager;
use Bartlett\Reflect\Provider\SymfonyFinderProvider;
use Bartlett\Reflect\Plugin\Cache\CachePlugin;
use Bartlett\Reflect\Plugin\Cache\DefaultCacheStorage;
use Bartlett\Reflect\Cache\DoctrineCacheAdapter;
use Doctrine\Common\Cache\FilesystemCache;
use Symfony\Component\Finder\Finder;
$dirs = '/path/to/source';
$finder = new Finder();
$finder->files()
->name('*.php')
->in($dirs);
$provider = new SymfonyFinderProvider($finder);
$pm = new ProviderManager;
$pm->set('dataSourceIdent', $provider);
$backend = new FilesystemCache(sys_get_temp_dir() . '/phpcompatinfo');
$doctrineCache = new DoctrineCacheAdapter($backend);
$cache = new DefaultCacheStorage($doctrineCache);
$compatinfo = new CompatInfo;
$compatinfo->setProviderManager($pm);
$compatinfo->addPlugin( new CachePlugin($cache) );
$compatinfo->parse();
Version 4.0
<?php
$loader = require_once dirname(__DIR__) . '/vendor/autoload.php';
$loader->addClassMap(
array(
'YourNamespace\CachePlugin'
=> __DIR__ . '/YourNamespace/CachePlugin.php',
)
);
use Bartlett\Reflect\Environment;
use Bartlett\Reflect\Client;
use Symfony\Component\EventDispatcher\GenericEvent;
// set our own location of JSON config file
putenv("BARTLETT_SCAN_DIR=" . __DIR__ . '/YourNamespace');
// set our own JSON config file
putenv("BARTLETTRC=yournamespace.json");
// creates an instance of client
$client = new Client();
// request for a Bartlett\Reflect\Api\Analyser
$api = $client->api('analyser');
// perform request, on a data source with default analyser (structure)
$dataSource = dirname(__DIR__) . '/src';
$analysers = array('structure');
// equivalent to CLI command `phpcompatinfo analyser:run ../src`
$metrics = $api->run($dataSource, $analysers);
var_export($metrics);
See full example in bartlett/php-reflect
package.
Listeners
Version 3.2
<?php
require_once 'vendor/autoload.php';
use Bartlett\CompatInfo;
use Bartlett\Reflect\ProviderManager;
use Bartlett\Reflect\Provider\SymfonyFinderProvider;
use Symfony\Component\Finder\Finder;
$dirs = '/path/to/source';
$finder = new Finder();
$finder->files()
->name('*.php')
->in($dirs);
$provider = new SymfonyFinderProvider($finder);
$pm = new ProviderManager;
$pm->set('dataSourceIdent', $provider);
$compatinfo = new CompatInfo;
$compatinfo->setProviderManager($pm);
$compatinfo->getEventDispatcher()->addListener(
'reflect.progress',
function (GenericEvent $e) {
printf(
'Parsing Data source "%s" in progress ... File "%s"' . PHP_EOL,
$e['source'],
$e['file']->getPathname()
);
}
);
$compatinfo->parse();
Version 4.0
<?php
require_once 'vendor/autoload.php';
use Bartlett\Reflect\Client;
use Bartlett\Reflect\Events;
use Symfony\Component\EventDispatcher\GenericEvent;
// creates an instance of client
$client = new Client();
// request for a Bartlett\Reflect\Api\Analyser
$api = $client->api('analyser');
$dispatcher = $api->getEventDispatcher();
$dispatcher->addListener(
Events::PROGRESS,
function (GenericEvent $e) {
printf(
'Parsing Data source "%s" in progress ... File "%s"' . PHP_EOL,
$e['source'],
$e['file']->getPathname()
);
}
);
// perform request, on a data source with default analyser (compatibility)
$dataSource = "/path/to/source';
$analysers = array('compatibility');
// equivalent to CLI command `phpcompatinfo analyser:run /path/to/source`
$metrics = $api->run($dataSource, $analysers);
var_export($metrics);
Exploring parsing results
Version 3.2
<?php
require_once 'Bartlett/PHP/CompatInfo/Autoload.php';
$source = '/path/to/source';
$options = array(
'cacheDriver' => 'null',
'recursive' => true
);
$compatinfo = new PHP_CompatInfo($options);
$compatinfo->parse($source);
$versions = $compatinfo->getVersions();
$classes = $compatinfo->getClasses();
$functions = $compatinfo->getFunctions();
$extensions = $compatinfo->getExtensions();
Version 4.0
<?php
require_once 'vendor/autoload.php';
use Bartlett\Reflect\Client;
// creates an instance of client
$client = new Client();
// request for a Bartlett\Reflect\Api\Analyser
$api = $client->api('analyser');
// perform request, on a data source with default analyser (compatibility)
$dataSource = '/path/to/source';
$analysers = array('compatibility');
// equivalent to CLI command `phpcompatinfo analyser:run /path/to/source`
$response = $api->run($dataSource, $analysers);
$metrics = $response['Bartlett\CompatInfo\Analyser\CompatibilityAnalyser'];
$versions = $metrics['versions'];
$classes = $metrics['classes'];
$functions = $metrics['functions'];
$extensions = $metrics['extensions'];