PHPackages                             loophp/service-alias-autoregister-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. loophp/service-alias-autoregister-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

loophp/service-alias-autoregister-bundle
========================================

Auto register services aliases in the Symfony container.

1.0.1(3y ago)17[1 issues](https://github.com/loophp/service-alias-autoregister-bundle/issues)[7 PRs](https://github.com/loophp/service-alias-autoregister-bundle/pulls)MITPHPPHP &gt;= 8.1CI failing

Since Nov 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/loophp/service-alias-autoregister-bundle)[ Packagist](https://packagist.org/packages/loophp/service-alias-autoregister-bundle)[ GitHub Sponsors](https://github.com/drupol)[ RSS](/packages/loophp-service-alias-autoregister-bundle/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (2)Dependencies (6)Versions (12)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/cf9b0483e5fa2211936fa85a3e2c5ce5b3227d867e4451ba9d22ad8dd5cb1241/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6f7068702f736572766963652d616c6961732d6175746f72656769737465722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/service-alias-autoregister-bundle)[![GitHub stars](https://camo.githubusercontent.com/a914bab013dcfc93d98787e58978ab8de1ce5d5c9fba9fdf52ef169b68386b7e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c6f6f7068702f736572766963652d616c6961732d6175746f72656769737465722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/service-alias-autoregister-bundle) [![Total Downloads](https://camo.githubusercontent.com/70e97d56d1c39dc91ee42fe72c29a93403e9cd25bb0a817e0ce04d828569f31e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6f7068702f736572766963652d616c6961732d6175746f72656769737465722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/service-alias-autoregister-bundle)[![License](https://camo.githubusercontent.com/69ef2acdb95b8db6ee8cf508258521760cdfbb5ebb034032cdecdb5fa009cb61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6f7068702f736572766963652d616c6961732d6175746f72656769737465722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/service-alias-autoregister-bundle) [![Donate!](https://camo.githubusercontent.com/a71f45de7e408be2477113d166e9ee94c90bbf814a1373fd154aa5b6652302de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d4769746875622d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/sponsors/drupol)

Service Alias Auto Register
===========================

[](#service-alias-auto-register)

A bundle for Symfony.

Description
-----------

[](#description)

The [S.O.L.I.D. principles](https://en.wikipedia.org/wiki/SOLID) are a quintet of design guidelines aimed at enhancing the clarity, flexibility, and maintainability of software designs. Among these is the [Open-Closed Principle](https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle), which advocates for the use of interfaces over concrete implementations.

In Symfony, the usual practice is to depend on concrete service implementations when injecting services, as opposed to utilizing an interface. Unfortunately, this approach compromises our code's flexibility and occasionally complicates testing.

Fortunately, this limitation can be overcome in Symfony by [manually introducing aliases](https://symfony.com/doc/current/service_container.html#binding-arguments-by-name-or-type) in the container for each class, a method that enhances flexibility and testing capabilities.

To rectify this issue and augment this practice, this bundle will declare new aliases in the Symfony container. Consequently, when a discovered service implements interfaces, aliases are automatically generated. For example, if a service implements three interfaces, the container will automatically create three new corresponding aliases.

These aliases are automatically created using the Fully Qualified Domain Name (FQDN) of the service's class when the discovered services implement one or several interfaces.

Leveraging aliases allows the injection of services using interfaces and named parameters instead of specific implementations, thereby addressing the often neglected Open-Closed Principle. In this way, our code becomes more adherent to S.O.L.I.D. principles, specifically the Open-Closed Principle, and hence more robust and easier to manage.

The following examples are showing an existing situation, as you can see, we do not respect that principle and we inject an concrete implementation directly:

```
