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

Container compilation and delegators #52

Closed karsten-sbs closed 2 years ago

karsten-sbs commented 2 years ago

I use several delegators in my project and if I define Config::DI_CACHE_PATH I get the error

Cannot compile closures which import variables using the use keyword
as mentioned in issue #45. The solution mentioned there isn't practicable in my case. I'd like to propose the following change to the Config class which eliminates the problem with the use keyword (and allows for type hinting the parameters):

                $current                      =
                    factory(function (ContainerInterface $container, RequestedEntry $requestedEntry, string $delegator, string $previous, string $name) {
                        $factory  = new $delegator();
                        $callable = function () use ($previous, $container) {
                            return $container->get($previous);
                        };
                        return $factory($container, $name, $callable);
                    })->parameter('delegator', $delegator)
                      ->parameter('previous', $previous)
                      ->parameter('name', $name);
elie29 commented 2 years ago

@karsten-sbs could you make the change and create a PR please? thx

karsten-sbs commented 2 years ago

Happy New Year, @elie29! I created a PR with my global account.

elie29 commented 2 years ago

@karsten-sbs happy new year, I will check it as soon as possible. Thank you