moddengine / Dice

Dice - a lightweight Dependency Injection Container for PHP
https://r.je/dice
7 stars 0 forks source link

False order construct arguments #8

Closed olekhy closed 1 year ago

olekhy commented 1 year ago

@cseufert after i made composer update and get latest v4.1.5 on my PC, then i get error: Argument 2 passed to Dummy::__construct() must be of the type array, string given my config

'Dummy'               => [
        'shared'          => true,
        'instanceOf'      => Dummy::class,
        'constructParams' => [
           'bar',
           ['a', 'b', 'c'],
           'foo',
        ],
    ],

one line from trace #0 [internal function]: Dummy->__construct('bar', 'foo', Array, '')

maybe u can fix this?

thx in advance

also commented here https://github.com/moddengine/Dice/commit/d6f16f4b4906007d5651468348482463a4397a40#diff-4a90bf98a876e67fa27cd2179554a48c237b9845d26937e07d967de3e3328dc8R434

cseufert commented 1 year ago

I cannot reproduce this with the following constructor signatures:

    public function __construct($a, array $list, $b)
    public function __construct($a, array $list, string $b = '')
    public function __construct(string $a, array $list, string $b)
    public function __construct(string $a = '', array $list = [], string $b = '')

Are you able to give me your Dummy class constructor signature?

olekhy commented 1 year ago

really simple php view renderer is used, _construct() signature: https://github.com/slimphp/PHP-View/blob/3.x/src/PhpRenderer.php#L31

DIC config

<?php

use Slim\Views\PhpRenderer;

return [
    '*'  => [
        'substitutions' => [         
            PhpRenderer::class => '$DefaultViewRenderer',
        ],
    ], 
   '$DefaultViewRenderer' => [
        'shared'  => true,
        'instanceOf' => PhpRenderer::class,
        'constructParams' => [
            '/tmp',
            [
              'varA' => 'A',
              'helpers' => ['helperA'],
            ],
            'layout.phtml',
        ],
    ],
];
olekhy commented 1 year ago

also php version:

$ php -v
PHP 7.4.30 (cli) (built: Sep 13 2022 11:08:45) ( NTS )
cseufert commented 1 year ago

This is now fixed in a new release: https://github.com/moddengine/Dice/releases/tag/v4.1.6

olekhy commented 1 year ago

@cseufert thx