Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dependency Injection Extra Laravel Package

maba/dependency-injection-extra

Extra compiler passes for Symfony Dependency Injection that register tagged services into a registry or other service, optionally passing tag attributes, service IDs, or priority-based ordering. Deprecated; use paysera/lib-dependency-injection instead.

View on GitHub
Deep Wiki
Context7

Extra for Symfony Dependency Injection Component

Deprecated

Please use paysera/lib-dependency-injection which provides more features than this library.

What's that?

Extra features for easier integration with Symfony Dependency Injection component.

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

AddTaggedCompilerPass

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

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.

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

You should probably stick to using lazy services, though.

AddTaggedByPriorityCompilerPass

Same as AddTaggedCompilerPass, but calls the method in the order defined in the priority attribute.

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

Lower the priority, earlier the call.

If priority is not provided, defaults to 0.

<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:

$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:

<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

composer update
vendor/bin/phpunit
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin