-
-
Notifications
You must be signed in to change notification settings - Fork 60
Description
RFC
| Q | A |
|---|---|
| Proposed Version(s) | 4.0.0 |
| BC Break? | Yes/No |
Goal
Allow users to have delegator factories for aliases.
Background
As of now, only delegator factories are applied to services registered to factories. In the past, we put services without its FQCN into the factories while aliasing the FQCN to that service name. That was done in laminas-cache, laminas-hydrator, etc.
In one minor release, that was changed which ended up being a BC break because upstream projects already registered delegator factories to these services. AFAIR that change got reverted afterwards.
Considerations
This would not require any change from upstream projects as only additional delegators are called.
Proposal(s)
I'd retrieve delegator factories for both service and alias (if aliased and requested via that alias).
Appendix
It might be problematic when it comes to aliases referring to aliases referring to aliases.
AFAIR, the ServiceManager resolves aliases until either a factory or an invokable could be found. Thats where we might lose information.
I'd say we can add this as a known limitation and still implement the feature.
Usually, the most common usecase is something like:
return [
'factories' => [
SystemClock::class => static fn () => new SystemClock(new DateTimeZone('Europe/Berlin')),
],
'aliases' => [
\Psr\Clock\ClockInterface::class => SystemClock::class,
],
'delegators' => [
\Psr\Clock\ClockInterface::class => [], // Add something which should be delegated whenever PSR-20 clock is being retrieved
SystemClock::class => [], // Whatever needs to be delegated regarding the system clock specific impl.
],
];