New in Symfony 3.3: PSR-11 containers

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.

Comments

Cool !
But ithink PSR-11 is not yet accepted !
@Karim It's very close to be : https://groups.google.com/forum/?fromgroups#!topic/php-fig/bU_iHdk38nE
Cool, thanks Grégoire
Well done!
Nice
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!
cool!
Nice !

Comments are closed.

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