Yii2: Integrate `yiisoft/di`

Created on 30 Dec 2017  路  13Comments  路  Source: yiisoft/yii2

DI container from yiisoft/di should be integrated into main repo replacing old DI classes before 2.1 release.
The location and internal code of the following classes should be rewised:

  • yii\di\Instance
  • yii\di\ServiceLocator

Keep in mind that namespace yii\di is taken by yiisoft/di package. While Composer allows having multiple folders for the same namespace, I would like to avoid such approach as it will make code navigation difficult.

PR for 'class' keyword fallback should be considered to be handled at yiisoft/yii instead of yiisoft/di. If there will be a graceful way to provide fallback from __class to class it could be done - if not - no fallback will be provided.

BC breaking task

All 13 comments

I think we can use it via composer instead of getting it into repository directly.

Obviously.

ServiceLocator could be moved to base.

Another thing is that yiisoft/di doesn't have built-in support for factories (should not be container job, I think) that we use for widgets.

We don't need Instance since there's Reference

What about Instance::ensure() then? It is widely used around the Yii code.

Yes. That's missing.

Intermediate changeset applied, allowing usage of '__class' keyword for definitions:
b04e0e06dc0939ae0b3c822656f1114f76ee320f
d1ff652b2f0baabbfb9e8776659167508eff5632

Thus the entire code will not break after "yiisoft/di" integration.

I'd suggest to implement __construct() parameter support as well.

  1. It is consistent with config format agreed for yiisoft/di
  2. While yiisoft/di is a bit raw and not integrated in Yii 2.1, this change will help us to write configs that will work after yiisoft/di adoption.

Please, consider reopening: #15815

Will this be PSR-11 compatible?

Yes, yiisoft/di is PSR-11 compatible.

After several attempts to integrate yiisoft/di by me, @SilverFire and @hiqsol which took too much time and weren't really successful decided not to do it. Instead:

  • [ ] Declare an interface for DI container in yiisoft/yii2. Make it an extension of PSR if possible.
  • [ ] Port cycles in dependencies detection from yiisoft/di.
  • [ ] Port method calls support from yiisoft/di.
  • [ ] Remove ability to set constructor options from method signatures, move it to __construct.

It's all indicated in roadmap so closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schmunk42 picture schmunk42  路  3Comments

sobit picture sobit  路  3Comments

SamMousa picture SamMousa  路  3Comments

MUTOgen picture MUTOgen  路  3Comments

chaintng picture chaintng  路  3Comments