ZF2-395: DI doesnt contruct object properly when default contructor param other then null
Description
Having this in config:
'di' => array(
'instance' => array(
'alias' => array(
'Session' => 'Zend\Session\Container',
,
),
),
And running $this->locator->get('Session') gives exception:
1) An abstract factory could not create an instance of session(alias: Session). 2) An exception was raised while creating "Session"; no instance returned 3)
Zend\Session\Exception\InvalidArgumentException
Soubor:
D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Session\Container.php:64
Zpráva:
Name passed to container is invalid; must consist of alphanumerics, backslashes and underscores only
Trasování zásobníku (Stack trace):
#0 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Di\Di.php(382): Zend\Session\Container->__construct(NULL, NULL)
#1 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Di\Di.php(204): Zend\Di\Di->createInstanceViaConstructor('Zend\Session\Co...', Array, 'Session')
#2 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Di\Di.php(153): Zend\Di\Di->newInstance('Session', Array)
#3 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\Di\DiServiceFactory.php(101): Zend\Di\Di->get('Session', Array)
#4 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\Di\DiAbstractServiceFactory.php(42): Zend\ServiceManager\Di\DiServiceFactory->get('Session', Array, true)
#5 [internal function]: Zend\ServiceManager\Di\DiAbstractServiceFactory->createServiceWithName(Object(Zend\ServiceManager\ServiceManager), 'session', 'Session')
#6 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(672): call_user_func(Array, Object(Zend\ServiceManager\ServiceManager), 'session', 'Session')
#7 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(803): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Array, 'session', 'Session')
#8 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(446): Zend\ServiceManager\ServiceManager->createFromAbstractFactory('session', 'Session')
#9 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(391): Zend\ServiceManager\ServiceManager->create(Array)
#10 D:\workspaces\Babysitting\ZendApplication\module\User\src\User\Controller\User.php(18): Zend\ServiceManager\ServiceManager->get('Session')
#11 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(137): User\Controller\User->loginAction()
#12 [internal function]: Zend\Mvc\Controller\AbstractActionController->execute(Object(Zend\Mvc\MvcEvent))
#13 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(453): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#14 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(193): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(104): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(139): Zend\Mvc\Controller\AbstractActionController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#17 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#18 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(453): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#19 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(193): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#20 D:\workspaces\Babysitting\ZendApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(305): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#21 D:\workspaces\Babysitting\ZendApplication\public\index.php(12): Zend\Mvc\Application->run()
#22 {main}
Seems it tries to contruct object with null params even they are all optional.
Expected behaviour same as if I put this into the config:
'service_manager' => array(
'invokables' => array(
'Session' => 'Zend\Session\Container',
),
),
Comments
Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:08.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2500