2017 © Pedro PelĆ”ez
 

library dependency-injection-extra

image

maba/dependency-injection-extra

  • Wednesday, November 22, 2017
  • by mariusbalcytis
  • Repository
  • 1 Watchers
  • 3 Stars
  • 170,280 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 20 % Grown

The README.md

Extra for Symfony Dependency Injection Component

Deprecated

Please use paysera/lib-dependency-injection which provides more features than this library., (*1)

What's that?

Extra features for easier integration with Symfony Dependency Injection component., (*2)

Currently contains only compiler passes for registering tagged services with some another service - no need to write custom class in each and every case., (*3)

AddTaggedCompilerPass

To register tagged services to some other service. Optionally passes attributes of the tag, too., (*4)

class SomeBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass(new AddTaggedCompilerPass(
            'some_bundle.registry',
            'my_provider',
            'addProvider',
            array(      // this parameter is optional and defines attributes to pass from tag
                'name',                 // required attribute
                'theme' => 'default',   // optional attribute
            )
        ));
    }
}
class Registry
{
    // first - tagged service. Others (optional) in the order as they come in the attributes array
    public function addProvider(ProviderInterface $provider, $name, $theme)
    {
        $this->providers[$name] = $provider;    // or whatever
    }
}
<service id="awesome_provider" class="Acme/AwesomeProvider">
    <tag name="my_provider" name="awesome"/>
</service>
<service id="nice_provider" class="Acme/NiceProvider">
    <tag name="my_provider" name="nice" theme="not a default one"/>
</service>

AddTaggedIdCompilerPass

Same, but first parameter to the method is not the service itself, but it's ID., (*5)

Gives some laziness if there are many tagged services and you don't use them all quite often., (*6)

You should probably stick to using lazy services, though., (*7)

AddTaggedByPriorityCompilerPass

Same as AddTaggedCompilerPass, but calls the method in the order defined in the priority attribute., (*8)

Attribute to use can be changed with $compilerPass->setPriorityAttribute('some_other')., (*9)

Lower the priority, earlier the call., (*10)

If priority is not provided, defaults to 0., (*11)

<service id="awesome_provider" class="Acme/AwesomeProvider">
    <tag name="my_provider" name="awesome" priority="9001"/>
</service>
<service id="nice_provider" class="Acme/NiceProvider">
    <tag name="my_provider" name="nice" theme="not a default one" priority="-1"/>
</service>
<service id="another_provider" class="Acme/AnotherProvider">
    <tag name="my_provider" name="another"/>
</service>

Resolves to:, (*12)

$registry->addProvider($niceProvider, 'nice', 'not a default one'); // priority -1 - smallest
$registry->addProvider($anotherProvider, 'another', 'default');     // priority defaults to 0
$registry->addProvider($awesomeProvider, 'awesome', 'default');     // priority is over 9000

Restrictions

Does not work well with several same tags on single service. Example:, (*13)

<service id="awesome_provider" class="Acme/AwesomeProvider">
    <tag name="my_provider" name="awesome"/>
    <tag name="my_provider" name="this will not be processed"/>
</service>

Installing

composer require maba/dependency-injection-extra

Running tests

Travis status Coverage Status, (*14)

composer update
vendor/bin/phpunit

The Versions

22/11 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

dependency injection di compiler pass

22/11 2017

0.1.2

0.1.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

dependency injection di compiler pass

22/11 2017

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

dependency injection di compiler pass

29/06 2016

0.1.1

0.1.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

dependency injection di compiler pass

24/07 2015

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marius Balčytis

dependency injection di compiler pass