Skip to content

make() fails when using decorate #554

@tsteur

Description

@tsteur

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions