1. Data Source Identification
Identify the Data Source with Symfony Finder.
Reflect offers a data source provider mechanism. You may either use the basic Symfony Finder, what we will do next, or use your own.
<?php
use Bartlett\Reflect\Provider\SymfonyFinderProvider;
use Symfony\Component\Finder\Finder;
$dirs = dirname(__DIR__) . '/sources';
$finder = new Finder();
$finder->files()
->name('*.php')
->in($dirs);
$provider = new SymfonyFinderProvider($finder);
At this step, we have created a data source provider that is allowed to retrieve each element to parse.
Reflect need to know it. We attach then the previous provider instance to a Provider Manager, with a label ( e.g: Single ) to identify it easily.
<?php
use Bartlett\Reflect\ProviderManager;
$pm = new ProviderManager;
$pm->set('Single', $provider);
A Provider Manager may provide one or more data source identifications. Here are another example with multiple data sources.
<?php
use Bartlett\Reflect\ProviderManager;
use Bartlett\Reflect\Provider\SymfonyFinderProvider;
use Symfony\Component\Finder\Finder;
$pm = new ProviderManager;
// -- source 1
$source1 = dirname(__DIR__) . '/sources/';
$finder1 = new Finder();
$finder1->files()
->name('sample1.php')
->in($source1);
$pm->set('Sample', new SymfonyFinderProvider($finder1));
// -- source 2
$pharFile = dirname(__DIR__) . '/sources/pirus.phar';
$source2 = 'phar://' . $pharFile;
$finder2 = new Finder();
$finder2->files()
->path('/Pirus/')
->name('*.php')
->in($source2);
$pm->set('Pirus', new SymfonyFinderProvider($finder2));
On this example Reflect is able to parse contents of two data sources: Sample and Pirus, all at once (default behavior) or individually.
2. Parse elements of the provider
We reuse the provider manager instance ($pm
) seen above (unique data source named Single ).
Then we ask Reflect to parse its full contents.
<?php
use Bartlett\Reflect;
$reflect = new Reflect;
$reflect->setProviderManager($pm);
$reflect->parse();
In case of multiple data sources, when you want to parse it individually rather than fully, use the following statements.
<?php
use Bartlett\Reflect;
$reflect = new Reflect;
$reflect->setProviderManager($pm);
$reflect->parse(array('Pirus'));
Pirus is the data source label used on $pm→set()
statement.
You have identified data sources and parsed its full contents. Now you are ready to handle the results.