New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make() fails when using decorate #554

Closed
tsteur opened this Issue Nov 24, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@tsteur
Contributor

tsteur commented Nov 24, 2017

Hi @mnapoli

I am getting currently this error with PHP-DI 5.4.5:

Entry "Piwik\Plugins\CoreHome\FooBar" cannot be resolved: Parameter $customer of __construct() has no value defined or guessableFull definition:Object ( class = Piwik\Plugins\CoreHome\FooBar scope = singleton lazy = false __construct( $customer = #UNDEFINED# ))

when calling:

            return $container->make('Piwik\Plugins\CoreHome\FooBar', array(
                'customer' => $customer
            ));

and having a DI config like:

'Piwik\Plugins\CoreHome\FooBar' => DI\decorate(function ($customer, \Interop\Container\ContainerInterface $c) {

        $myTest = $c->get('test.vars.myTest');
        if (!empty($myTest)) {
            return new MyTest();
        }

        return $customer;
    }),

The class looks like this:

class FooBar {
    /**
     * @var array
     */
    private $customer;

    public function __construct($customer)
    {
        $this->customer = $customer;
    }

It works nicely as soon as I remove the DI\decorate() but not when I add it. It does not even go into the decorator when debugging it.

It fails in ObjectCreator::createInstance() with a DefinitionException.

It seems like the passed parameters get lost in DecoratorResolver::resolve(Definition $definition, array $parameters = []) where the $parameters are actually never used.

tsteur added a commit to tsteur/PHP-DI that referenced this issue Nov 24, 2017

Fix make() fails when using decorate
fixes PHP-DI#554

@mnapoli looks like this may fix my issue

tsteur added a commit to tsteur/PHP-DI that referenced this issue Nov 24, 2017

Fix make() fails when using decorate
fixes PHP-DI#554

@mnapoli looks like this might fix the issue

tsteur added a commit to tsteur/PHP-DI that referenced this issue Nov 27, 2017

@mnapoli mnapoli closed this in 424f4cd Dec 3, 2017

mnapoli added a commit that referenced this issue Dec 3, 2017

Add test for #554
Port #556 into master for PHP-DI 6.
@mnapoli

This comment has been minimized.

Member

mnapoli commented Dec 3, 2017

I've released 5.4.6 which contains the fix.

@mnapoli mnapoli added the bug label Dec 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment