Coder Social home page Coder Social logo

discovery's Introduction

The Puli Discovery Component

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

Latest release: 1.0.0-beta8

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:

use Puli\Discovery\Api\Type\BindingType;
use Puli\Discovery\Binding\Initializer\ResourceBindingInitializer;
use Puli\Discovery\InMemoryDiscovery;

$discovery = new InMemoryDiscovery(array(
    // $repo is a Puli\Repository\Api\ResourceRepository instance
    new ResourceBindingInitializer($repo),
));

$discovery->addBindingType(new BindingType('doctrine/xml-mapping'));

Resource Bindings

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

use Puli\Discovery\Binding\ResourceBinding;

$discovery->addBinding(new ResourceBinding('/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(new BindingType(Plugin::class));

Classes can be bound by adding ClassBinding instances:

use Puli\Discovery\Binding\ClassBinding;

$discovery->addBinding(new ClassBinding(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 [email protected] or shout out to @webmozart on Twitter.

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.