Generated by GPT-5-mini| PSR-11 | |
|---|---|
| Name | PSR-11 |
| Type | Specification |
| Status | Final |
| Version | 1.0 |
| Organization | PHP Framework Interop Group |
| Domain | Dependency Injection |
PSR-11
PSR-11 is a PHP specification published by the PHP Framework Interop Group that defines a common container interface for retrieving entries from a container. It aims to enable interoperability between Laravel, Symfony, Zend Framework, Slim, Drupal and other Composer-managed libraries by standardizing method signatures and exception behavior. PSR-11 facilitates integration across middleware ecosystems like Zend Expressive, routing stacks such as FastRoute, and testing tools like PHPUnit.
PSR-11 standardizes two core interactions: retrieving an entry by identifier and checking for an entry's existence, aligning expectations across implementations used by Symfony Console, Laravel Nova, Craft CMS, WordPress, and Drupal Console. The specification references common PHP concepts used in projects like Composer, Packagist, GitHub, GitLab, and Bitbucket to ensure compatibility with package distribution workflows and continuous integration systems such as Travis CI, Jenkins, and GitHub Actions. PSR-11's scope intentionally excludes service definition formats found in Symfony DependencyInjection, Pimple, Aura.Di and focuses on runtime container interaction relevant to frameworks like Zend Expressive and applications using PSR-7 middleware patterns championed by PHP-FIG.
The specification mandates two methods: one for retrieving a service by its identifier and one for checking presence, mirroring conventions seen in APIs like PSR-3 logging adapters and PSR-6 caching pools used by Memcached, Redis, and Doctrine Cache. PSR-11 requires that implementations throw specific exceptions (akin to patterns in Symfony Exception handling and Monolog error reporting) when entries are absent or when retrieval fails, facilitating integration with error reporting services such as Sentry, New Relic, and Bugsnag. The interface design aligns with object-oriented principles advocated by authors and practitioners like Rasmus Lerdorf, Nikita Popov, and organizations like Zend Technologies and Symfony Project to ensure predictable behavior in projects like Magento, TYPO3, and Laravel Horizon.
Multiple implementations exist across ecosystems: adapters in Symfony's container, bridge packages for Laravel, lightweight containers like Pimple adapters, and enterprise solutions in Laminas Project components. Community implementations are available via Packagist repositories and are integrated in scaffolding tools such as Composer scripts and Robo tasks. Third-party libraries used in projects like Drupal, Magento and OctoberCMS expose PSR-11 compatible containers to enable interoperability with middleware stacks like Relay and routing libraries including FastRoute.
Typical usage appears in request handling pipelines where a router like FastRoute resolves a controller that is fetched from a container used by frameworks including Slim, Zend Expressive, or Silex. Integration examples exist in CLI tools such as Symfony Console commands and in background job runners like Supervisor-managed daemons. Examples demonstrate retrieving services used by components like Twig, Doctrine, Monolog handlers, and Guzzle clients, enabling wiring in applications like Laravel Nova, Shopware, Magento, and Drupal.
PSR-11 was designed to interoperate with related FIG standards including PSR-3, PSR-6, PSR-7, and PSR-4 autoloading conventions embraced by Composer and Packagist. It is used in ecosystems that include frameworks such as Symfony, Laravel, Laminas Project, Slim, CakePHP, and CMSs like Drupal and WordPress via plugin adapters. The specification's exception policies help unify behavior across error monitoring services like Sentry, New Relic, and Datadog, and testing with PHPUnit or Behat.
PSR-11 was developed within the PHP Framework Interop Group, building on earlier FIG work such as PSR-0 and PSR-4 to improve library interoperability across ecosystems represented by maintainers from Symfony, Zend Technologies, Laravel, Drupal, and independent projects hosted on GitHub. Adoption grew in frameworks and projects like Symfony, Laravel, Laminas Project, Slim, Drupal, and package repositories on Packagist, aided by integration examples in GitHub Actions workflows and community discussions on platforms such as Stack Overflow and PHP-FIG mailing lists. The specification continues to influence container contracts and inter-framework tooling in the PHP ecosystem.