elie29 / zend-di-config

PSR-11 PHP-DI container configurator for Laminas, Mezzio, ZF, Expressive applications or any framework that needs a PSR-11 container
MIT License
19 stars 4 forks source link

Allow to declare custom definitions #27

Closed thomasvargiu closed 5 years ago

thomasvargiu commented 5 years ago

It would be useful a config key which allows to set custom service definitions.

Something like:

return [
    'dependencies' => [
        'definitions' => [
            MyClass::class => DI\create(MyClass::class)->lazy(),
        ],
    ],
];

This will allow to use a configuration to define services in different modules when you use a modular structure.

elie29 commented 5 years ago

@thomasvargiu thank you for the proposal.

Do you want to do it so I assigne it to you?

elie29 commented 5 years ago

It occurs changes in: config, tests, Readme file and suggestion in composer for lazy dependencies

thomasvargiu commented 5 years ago

@elie29 I could work on it. It's a missed feature, a reason why I tried php-di to move then back to zend-servicemanager with zend-di AoT.

I have just a question. I think IMHO that something not related to map zend-servicemanger configuration to php-di should be moved in another configuration key. What do you think?

elie29 commented 5 years ago

Well you are totally right. dependencies keys are mapped to zend service manager (except autowires). So we can have defintions key at the same level of dependencies and not inside it.

elie29 commented 5 years ago
return [
  'definitions' => [
    MyClass::class => DI\create(MyClass::class)->lazy(),
  ],
  'dependencies' => [],
];
thomasvargiu commented 5 years ago

definitions is a common key. In the last years projects are using namespace keys as configuration key, so it would be better to use a class namespace to use as a key to avoid conflicts, something like:

return [
    Zend\DI\Config::class => [
        'definitions' => [],
    ],
];

But I think we should resolve #28 first, that's why I open it.

elie29 commented 5 years ago

Right! should we need for definitions inside the classname key?

thomasvargiu commented 5 years ago

Yes, it's better to make all BC break changes in just one release, we don't need to release something today :)

I suggest to resolve #28 and this PR and release them in a single major release.

elie29 commented 5 years ago

@thomasvargiu 4.0 created.