PHPackages                             paysera/lib-dependency-injection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. paysera/lib-dependency-injection

ActiveLibrary[Framework](/categories/framework)

paysera/lib-dependency-injection
================================

Helper classes for Symfony Dependency Injection component

1.4.0(2y ago)243.7k↓64.9%35MITPHPPHP ^7.0 | ^8.0

Since Jan 9Pushed 2y ago7 watchersCompare

[ Source](https://github.com/paysera/lib-dependency-injection)[ Packagist](https://packagist.org/packages/paysera/lib-dependency-injection)[ RSS](/packages/paysera-lib-dependency-injection/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (3)Versions (10)Used By (5)

Helper classes for Symfony Dependency Injection component
=========================================================

[](#helper-classes-for-symfony-dependency-injection-component)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e746fe40c6cfc5ad97ab7ad995ea6b639574103a47a0e2a86e5973148345098e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706179736572612f6c69622d646570656e64656e63792d696e6a656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paysera/lib-dependency-injection)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/0de6b63057f3943813f918eaaf387dea60c5ee95623a46c4173db794d0b63a1e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f706179736572612f6c69622d646570656e64656e63792d696e6a656374696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/paysera/lib-dependency-injection)[![Coverage Status](https://camo.githubusercontent.com/e0777a3e65f8663715cf3cac68434050cb0216678afaa9f4c6cbbe469c45893f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f706179736572612f6c69622d646570656e64656e63792d696e6a656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/paysera/lib-dependency-injection/code-structure)[![Quality Score](https://camo.githubusercontent.com/c1e425bc66aa33c15665b774c30f9d5fde8f4c4a9a09d50c5d254f1c7285af56/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706179736572612f6c69622d646570656e64656e63792d696e6a656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/paysera/lib-dependency-injection)[![Total Downloads](https://camo.githubusercontent.com/b9ff3b97a7ef61bbbb535a89a8b057847d3c1c56d79ef3bbc53fe2b64779cb9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706179736572612f6c69622d646570656e64656e63792d696e6a656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paysera/lib-dependency-injection)

What is this?
-------------

[](#what-is-this)

Extra features for easier integration with Symfony Dependency Injection component.

Contains compiler pass for registering tagged services with some another service - no need to write custom class in each and every case.

Installation
------------

[](#installation)

```
composer require paysera/lib-dependency-injection
```

### Basic functionality

[](#basic-functionality)

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', // ID of service to modify
            'my_provider',          // name of tag to search for
            'addProvider',          // method to call on modified service
            [           // this parameter is optional and defines attributes to pass from tag
                'key',
                'theme' => 'default',   // attribute with default value
                'optional',
            ]
        ));
    }
}
```

```
class Registry
{
    // first - tagged service. Others (optional) in the order as they come in the attributes array
    public function addProvider(ProviderInterface $provider, $key, $theme, $optional = null)
    {
        $this->providers[$key] = $provider;    // or whatever
    }
}
```

```

    Any arguments service might have

```

### Using priority

[](#using-priority)

Sometimes we need to call method with tagged services by some pre-defined priority. We could prioritize in the service itself, but this makes code duplicated and also is not as quick as ordering in compile-time – no need to sort anything in the run-time.

Priority should be enabled when registering compiler pass. It's provided in `priority` attribute. Lower the priority, earlier the call. If priority is not provided, defaults to `0`.

```
class SomeBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass((new AddTaggedCompilerPass(
            'some_bundle.registry', // ID of service to modify
            'my_provider',          // name of tag to search for
            'addProvider',          // method to call on modified service
            ['key', 'theme' => 'default', 'optional'],
        ))->enablePriority()); // attribute name can be passed here, defaults to `priority`
    }
}
```

```

```

Resolves to:

```
// priority -1 - smallest:
$registry->addProvider($niceProvider, 'nice', 'dark');
// priority defaults to 0, called in the order as registered:
$registry->addProvider($awesomeProvider, 'awesome', 'default');
$registry->addProvider($anotherProvider, 'another', 'default');
// priority is over 9000:
$registry->addProvider($awesomeProvider, 'fallback', 'default', 'optional param');
```

### Tuning performance

[](#tuning-performance)

When adding many services by method calls, all of them need to be created when instantiating the collector service. This could get troublesome if number of services is high.

This is why you can configure a few options to use instead of just passing the service:

- `lazy_service` – pass the service as normally, but mark all services lazy. This makes it faster in production in most cases, but can be quite slow in development, as container must be rebuilt every time you modify any of those services (even the code itself);
- `id` – pass only ID of the service, also make tagged service public. This requires you to inject `container` into your collector and get services by ID when needed.

```
class SomeBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass((new AddTaggedCompilerPass(
            'some_bundle.registry', // ID of service to modify
            'my_provider',          // name of tag to search for
            'addProvider',          // method to call on modified service
            ['key', 'theme' => 'default', 'optional'],
        ))->setCallMode(AddTaggedCompilerPass::CALL_MODE_ID));
    }
}
```

```
class Registry
{
    private $container;

    public function addProvider(string $providerId, $key, $theme, $optional = null)
    {
        $this->providers[$key] = $providerId;
    }

    private function getProvider(string $key)
    {
        return $this->container->get($this->providers[$key]);
    }

    // ...
}
```

Semantic versioning
-------------------

[](#semantic-versioning)

This library follows [semantic versioning](http://semver.org/spec/v2.0.0.html).

See [Symfony BC rules](http://symfony.com/doc/current/contributing/code/bc.html) for basic information about what can be changed and what not in the API.

Running tests
-------------

[](#running-tests)

```
composer update
composer test

```

Contributing
------------

[](#contributing)

Feel free to create issues and give pull requests.

You can fix any code style issues using this command:

```
composer fix-cs

```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~418 days

Recently: every ~268 days

Total

7

Last Release

953d ago

PHP version history (4 changes)1.0.0PHP &gt;=5.3.3

1.1.0PHP &gt;=7.0

1.2.0PHP ^7.0

1.3.0PHP ^7.0 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d385187c2b529d5c1189dfc3763972f76738d24293593ff3db876fff82321db?d=identicon)[paysera.com](/maintainers/paysera.com)

---

Top Contributors

[![mariusbalcytis](https://avatars.githubusercontent.com/u/1590072?v=4)](https://github.com/mariusbalcytis "mariusbalcytis (2 commits)")[![desislavaggeorgieva](https://avatars.githubusercontent.com/u/69151016?v=4)](https://github.com/desislavaggeorgieva "desislavaggeorgieva (1 commits)")[![dmihaylov92](https://avatars.githubusercontent.com/u/5844413?v=4)](https://github.com/dmihaylov92 "dmihaylov92 (1 commits)")[![ypppa](https://avatars.githubusercontent.com/u/5552596?v=4)](https://github.com/ypppa "ypppa (1 commits)")

---

Tags

didiccompilertagstagservicescompilerpasspassprioritydependencyinjection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paysera-lib-dependency-injection/health.svg)

```
[![Health](https://phpackages.com/badges/paysera-lib-dependency-injection/health.svg)](https://phpackages.com/packages/paysera-lib-dependency-injection)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
