You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make it possible to use another PSR-11 compatible container.
Original issue:
This is related to my open PR(#14107) regarding PSR-11 compatibility, it is not the same however.
My PR is about making the Yii DI container usable in libraries that need a PSR-11 container.
This is to be a discussion about supporting other DI containers for usage within Yii.
Yii's DI container does some things that are out of the scope of PSR-11.
These are:
Allowing to not only resolve dependencies for objects but also for callables.
Allow configuring of objects via ->get(..., ..., ...).
Allow passing constructor arguments to the object that must be returned.
Note that (1) and (2) can be refactored to wrap any PSR-11 container instead of being part of a container itself. (3) however is a problem. Since $container->get() will return the object there is no option to pass constructor arguments, for these cases we need to look for alternatives (which is why this is a 2.1 discussion).
There are currently 5 places in the Yii source code that pass constructor arguments to $container->get via Yii::createObject:
In these specific cases the constructor arguments consist of public variables combined with a configuration array. The reason for these variables to be constructor arguments (they could also be configured via the configuration array) is that they are not optional but required.
I do not have a specific solution that I feel is best, but I think the above provides enough information to start a discussion.
tldr; if we want Yii to be able to use PSR-11 DI Containers we must:
Decide how to handle constructor arguments outside DI
Decide how to handle configuration outside DI
The text was updated successfully, but these errors were encountered:
only more than 5 cases need to refactor, example look web\User component and how create url in loginRequired. If i can override user component in AccessFilter, but not override Url::to in loginRequired
samdark
changed the title
[2.1] Support different DI containers.
[2.1] Make Container PSR-11 compatible, support different PSR-11 DI containers
Sep 7, 2017
TODO:
Original issue:
This is related to my open PR(#14107) regarding PSR-11 compatibility, it is not the same however.
My PR is about making the Yii DI container usable in libraries that need a PSR-11 container.
This is to be a discussion about supporting other DI containers for usage within Yii.
Yii's DI container does some things that are out of the scope of PSR-11.
These are:
->get(..., ..., ...)
.Note that (1) and (2) can be refactored to wrap any PSR-11 container instead of being part of a container itself. (3) however is a problem. Since
$container->get()
will return the object there is no option to pass constructor arguments, for these cases we need to look for alternatives (which is why this is a 2.1 discussion).There are currently 5 places in the Yii source code that pass constructor arguments to
$container->get
viaYii::createObject
:These 5 calls instantiate (subclasses of) 3 classes:
In these specific cases the constructor arguments consist of public variables combined with a configuration array. The reason for these variables to be constructor arguments (they could also be configured via the configuration array) is that they are not optional but required.
I do not have a specific solution that I feel is best, but I think the above provides enough information to start a discussion.
tldr; if we want Yii to be able to use PSR-11 DI Containers we must:
The text was updated successfully, but these errors were encountered: