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.
Contributions to Puli are always welcome!
- Report any bugs or issues you find on the issue tracker.
- You can grab the source code at Puli’s Git repository.
If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter.
All contents of this package are licensed under the MIT license.