PHP code example of puli / discovery

1. Go to this page and download the library: Download puli/discovery library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

puli / discovery example snippets


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'));

use Puli\Discovery\Binding\ResourceBinding;

$discovery->addBinding(new ResourceBinding('/app/config/doctrine/*.xml', 'doctrine/xml-mapping'));

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

$discovery->addBindingType(new BindingType(Plugin::class));

use Puli\Discovery\Binding\ClassBinding;

$discovery->addBinding(new ClassBinding(MyPlugin::class, Plugin::class));

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