Skip to content
/ discovery Public
forked from puli/discovery

Discovers Puli resources bound to predefined types.

License

Notifications You must be signed in to change notification settings

stof/discovery

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Puli Resource Discovery

Build Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads Dependency Status

Latest release: none

PHP >= 5.3.9

The Puli Discovery component supports binding of Puli resources to types. Types can be defined with the define() method of the ResourceBinder:

use Puli\Discovery\ResourceBinder;

// $repo is a Puli repository
$binder = new ResourceBinder($repo);

$binder->define('acme/xliff-messages');

Resources in the repository can be bound to defined types with the bind() method:

$binder->bind('/app/trans/*.xlf', 'acme/xliff-messages');

You can define parameters for binding types:

use Puli\Discovery\Binding\BindingParameter;
use Puli\Discovery\Binding\BindingType;

$binder->define(new BindingType('acme/xliff-messages', array(
    new BindingParameter('translationDomain'),
)));

$binder->bind('/app/trans/errors.*.xlf', 'acme/xliff-messages', array(
    'translationDomain' => 'errors',
));

The bindings can later be fetched with the find() method:

$bindings = $binder->find('acme/xliff-messages');

foreach ($bindings as $binding) {
    foreach ($binding->getResources() as $resource) {
        $translator->add($resource->getLocalPath(), $binding->getParameter('translationDomain'));
    }
}

To optimize read performance, you should write the binder to a storage. The stored object is of type ResourceDiscoveryInterface which only supports read access:

use Puli\Discovery\Storage\PhpDiscoveryStorage;

$storage = new PhpDiscoveryStorage();

// run once
$storage->storeDiscovery($binder, array('path' => '/path/to/discovery.php'));

// run whenever bindings need to be accessed
$discovery = $storage->loadDiscovery($repo, array('path' => '/path/to/discovery.php'));

$bindings = $discovery->find('acme/xliff-messages');
// ...

Read Puli at a Glance if you want to learn more about Puli.

Authors

Contribute

Contributions to Puli are always welcome!

Support

If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter.

License

All contents of this package are licensed under the MIT license.

About

Discovers Puli resources bound to predefined types.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%