Do not implement PSR-11
- Created
- Decided
- Versions
- History
Context
PSR-11 is PHP's shared container interface: get() and has(), each keyed by a string identifier. What it offers is
interchangeability. An application can swap one container for another, and a library written against the interface
works with any container that implements it.
The panel is not a framework. It is one purpose-built system distributed as a single binary. Nobody replaces its container, and nothing outside the panel integrates with it at the level of the container.
Decision
I will not implement PSR-11. Code that wants something from the container will describe it with the container's own
resolution and invocation objects rather than a string passed
to get(), and no part of the panel will depend on the Psr\Container interfaces.
Alternatives
Implementing PSR-11 alongside the container's own API, so that a library written against the interface could be handed the panel's container. I rejected this because interchangeability buys nothing in a bespoke system shipped as a single binary. The PSRs are also dated, and implementing one bends a design into its shape, where the container can instead be shaped around what the panel needs.
Whether this was weighed at the time, or simply never adopted, is not recorded.
Consequences
Easier:
- The container's API will follow what the panel needs. A resolution will carry its name, qualifier, arguments, and whether it is lazy or liminal as part of the request, rather than packing them into a string.
Harder:
- A library that expects a PSR-11 container will not be able to use the panel's.
Constrained:
- Components will depend on the container's own API, and on nothing from PSR-11.
Sources
- Commit bdc32d7, "Initial dependency injection work", : the first code of the container, without
PSR-11, which is
created. - PR #23, feat(container): Dependency Injection, merged : the container merged without PSR-11, which is
decided. When the decision was taken is not recorded. - The decision and its reasons, that PSR-11's interchangeability does not apply to a bespoke system shipped as a single binary and that PSRs are dated and constrain design: first written down on .
- Issue #31, Engine - Config - TOML, original text of in its edit history: the first written record of the panel being distributed as a binary, two days after this decision's date.
composer.jsonat 728ad64: no dependency onpsr/container.
Source adr/0004-no-psr-11.md · commit d6910e4 · exported