Quick Start

This quick start is a five minute tutorial where you can discover how to identify a data source.

1. Data Source Identification

Identify the Data Source with Symfony Finder.

Now, and for the following chapters, we will not mention how you load the classes. See the strategy you’ve adopted in the Setup chapter.
CompatInfo and Reflect share the same data source provider strategy.

CompatInfo offers a data source provider mechanism. You may either use the basic Symfony Finder, what we will do next, or use your own.

Basic Provider with Symfony Finder
<?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 analyse.

CompatInfo 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.

Provider Manager with a unique data source
<?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.

Provider Manager 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 CompatInfo is able to analyse contents of two data sources: Sample and Pirus, all at once (default behavior) or individually.

2. Analyse elements of the provider

We reuse the provider manager instance ($pm) seen above (unique data source named Single ). Then we ask CompatInfo to analyse its full contents.

<?php

use Bartlett\CompatInfo;

$compatinfo = new CompatInfo;
$compatinfo->setProviderManager($pm);
$compatinfo->parse();

In case of multiple data sources, when you want to parse it individually rather than fully, use the following statements.

Analyse only Data Source #2
<?php

use Bartlett\CompatInfo;

$compatinfo = new CompatInfo;
$compatinfo->setProviderManager($pm);
$compatinfo->parse(array('Pirus'));

Pirus is the data source label used on $pm→set() statement.

You have identified data sources and analyse its full contents. Now you are ready to handle the results.

To be continued … on stable version 3.1