Skip to content

Repository files navigation

The Puli Discovery Component

Build StatusBuild statusScrutinizer Code QualityLatest Stable VersionTotal DownloadsDependency Status

Latest release: 1.0.0-beta9

PHP >= 5.3.9

The Puli Discovery Component supports binding of Puli resources to binding types. Binding types can be defined with the addBindingType() method of the EditableDiscovery interface:

usePuli\Discovery\Api\Type\BindingType;
usePuli\Discovery\Binding\Initializer\ResourceBindingInitializer;
usePuli\Discovery\InMemoryDiscovery;
$discovery = newInMemoryDiscovery(array(
// $repo is a Puli\Repository\Api\ResourceRepository instancenewResourceBindingInitializer($repo),
));
$discovery->addBindingType(newBindingType('doctrine/xml-mapping'));

Resource Bindings

Resources in the repository can then be bound to the defined type by passing a ResourceBinding to addBinding():

usePuli\Discovery\Binding\ResourceBinding;
$discovery->addBinding(newResourceBinding('/app/config/doctrine/*.xml', 'doctrine/xml-mapping'));

With findBindings(), you can later retrieve all the bindings for the type:

foreach ($discovery->findBindings('doctrine/xml-mapping') as$binding) {
foreach ($binding->getResources() as$resource) {
// do something...
}
}

The following Discovery implementations are currently supported:

Read the Resource Discovery guide in the Puli documentation to learn more about resource discovery.

Class Bindings

You can also bind classes to binding types. By convention, the common interface of all bound classes is used as binding type:

$discovery->addBindingType(newBindingType(Plugin::class));

Classes can be bound by adding ClassBinding instances:

usePuli\Discovery\Binding\ClassBinding;
$discovery->addBinding(newClassBinding(MyPlugin::class, Plugin::class));

As before, use findBindings() to find all bindings for a binding type:

foreach ($discovery->findBindings(Plugin::class) as$binding) {
$pluginClass = $binding->getClassName();
$plugin = new$pluginClass();
// do something...
}

Authors

Installation

Follow the Installation guide guide to install Puli in your project.

Documentation

Read the Puli Documentation to learn more about Puli.

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

Publishes and discovers artifacts across Puli packages.

Resources

Stars

11 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages