Skip to content
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

[3.0.1] Dependency injection - Argument at position 0 must have a type #12294

Closed
Zaszczyk opened this issue Oct 6, 2016 · 2 comments
Closed

Comments

@Zaszczyk
Copy link
Contributor

Zaszczyk commented Oct 6, 2016

I found problem with nested dependency injection. I have such configuration:

$di->setShared('Activity\ActivityAddingService', [
    'className' => 'XXX\Models\Services\Service\Activity\ActivityAddingService',
    'arguments' => [
        [
            'type' => 'service',
            'name' => 'Activity\ActivityParameterService',
        ],
    ]
]);

$di->setShared('Activity\ActivityParameterService', [
    'className' => 'XXX\Models\Services\Service\Activity\ActivityParameterService',
    'arguments' => [
        'type' => 'service',
        'name' => 'Activity\ActivityParameterRepository',
    ]
]);

$di->setShared('Activity\ActivityParameterRepository', [
    'className' => 'XXX\Models\Repositories\Repository\Activity\ActivityParameterRepository'
]);

And Phalcon throw exception when I execute:
$this->getDI->get('Activity\ActivityAddingService');

Exception:

Argument at position 0 must have a type
/var/www/xxx/www/apps/modules/company/controllers/Activity/ActivityController.php:141
0

0 [internal function]: Phalcon\Di\Service\Builder->_buildParameter(Object(Phalcon\Di\FactoryDefault), 'type', 'service')

1 [internal function]: Phalcon\Di\Service\Builder->_buildParameters(Object(Phalcon\Di\FactoryDefault), Array)

2 [internal function]: Phalcon\Di\Service\Builder->build(Object(Phalcon\Di\FactoryDefault), Array, NULL)

3 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))

4 [internal function]: Phalcon\Di->get('Activity\Activi...')

5 [internal function]: Phalcon\Di\Service\Builder->_buildParameter(Object(Phalcon\Di\FactoryDefault), 0, Array)

6 [internal function]: Phalcon\Di\Service\Builder->_buildParameters(Object(Phalcon\Di\FactoryDefault), Array)

7 [internal function]: Phalcon\Di\Service\Builder->build(Object(Phalcon\Di\FactoryDefault), Array, NULL)

8 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))

9 /var/www/xxx/www/apps/modules/company/controllers/Activity/ActivityController.php(141): Phalcon\Di->get('Activity\Activi...')

10 [internal function]: Modules\Company\Controllers\Activity\ActivityController->addAction()

11 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(Modules\Company\Controllers\Activity\ActivityController), 'addAction', Array)

12 [internal function]: Phalcon\Dispatcher->_dispatch()

13 [internal function]: Phalcon\Dispatcher->dispatch()

14 /var/www/xxx/www/public/index.php(24): Phalcon\Mvc\Application->handle()

15 {main}

However when I remove argument from Activity\ActivityParameterService, like that:

$di->setShared('Activity\ActivityParameterService', [
    'className' => 'XXX\Models\Services\Service\Activity\ActivityParameterService',
]);

I found line with exception:

throw new Exception("Argument at position " . position . " must have a type");

It works fine, it seems to be problem with nested calling services from DI.
I've tested at:
-PHP 5.6 and 2.0.x, Ubuntu
-PHP 7.0 and 3.0.1, Ubuntu
The same results.

@andrew-demb
Copy link
Contributor

The value of arguments in definition service must be an array of arrays.
Now it's only one-dimensional array.

@Zaszczyk
Copy link
Contributor Author

Zaszczyk commented Oct 6, 2016

@andrew-demb damn me... thanks!

@Zaszczyk Zaszczyk closed this as completed Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants