New in Symfony 3.3: PSR-11 containers

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

Contributed by
Grégoire Paris
in #21265.

Symfony project implements lots of PHP-FIG PSR standards, such as PSR-2 (code styling), PSR-3 (Logger interface), PSR-4 (autoloader), PSR-6 (caching interface) and PSR-16 (simple cache).

Implementing industry standards improves interoperability and reduces the learning curve. That's why in Symfony 3.3 we decided to implement another standard called PSR-11: Container Interface.

PSR-11 defines a simple API that service containers must implement. In practice, this standard won't impact your existing Symfony applications. For starters, the public API only defines two methods called get() and has() which are named and behave in the same way as the Symfony methods that you know and use.

In addition, containers must now implement Psr\Container\ContainerInterface, so we've made our ContainerInterface extend from it. Moreover, the PSR-11 standard defines two new exceptions: ContainerExceptionInterface (implemented by our ExceptionInterface) and NotFoundExceptionInterface (implemented by our ServiceNotFoundException).

Although this new feature won't require any changes in your applications, it will unlock the implementation of other Symfony features, such as better service locators, as explained in an upcoming blog post.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Cool !
But ithink PSR-11 is not yet accepted !
@Karim It's very close to be :!topic/php-fig/bU_iHdk38nE
Cool, thanks Grégoire
Well done!
It's all cool. There seems to be almost no impact at all. This just makes Symfony, officially, PSR-11 compliant.
Common interface for dependency injection container. Very good idea to continue with PSR
It looks only small changes are required, nice!
Nice !

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.