i got a strange problem with the ZF2.
Im configuring my Service Manager this way:
module.config.php ...
- Code: Select all
<?php
return array(
//...
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'Bricks\Widget' => 'Bricks\Widget\WidgetFactory',
),
),
//...
);
The belonging class Bricks\Widget\WidgetFactory.php ...
- Code: Select all
<?php
namespace BricksWidget;
use ZendServiceManagerFactoryInterface;
use ZendServiceManagerServiceLocatorInterface;
class WidgetFactory implements FactoryInterface {
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $sl->get('Configuration');
$widgets = $config->widget;
die(var_dump($widgets,__FILE__,__LINE__));
}
}
I expect the dump of the configuration parameters.
But this class will never be instanciated due an ServiceNotFoundException if i call the class through the ServiceManager.
I've checked Zend\ServiceManager\Config.php if the factory will be setted and in fact the factory will be stored on the ServiceManager.
The file where i call the ServiceManager Bricks\View\Helper\Widgets.php ...
- Code: Select all
<?php
namespace BricksViewHelper;
use ZendViewHelperAbstractHtmlElement;
use ZendServiceManagerServiceLocatorAwareInterface;
use ZendServiceManagerServiceLocatorInterface;
class Widgets extends AbstractHtmlElement implements
ServiceLocatorAwareInterface
{
/**
* @var ServiceLocator
*/
protected $serviceLocator;
/**
* Set the service locator.
*
* @param ServiceLocator $serviceLocator
* @return Widget
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
/**
* Get the service locator.
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
public function __invoke()
{
$sl = $this->getServiceLocator();
die(var_dump($sl->has('Bricks\Widget')));
$sl = $sm->get('widget');
die(var_dump(get_class($sl),__FILE__,__LINE__));
}
}
it outputs bool(false)
In Conclusion:
The ServiceManager will be setted up correctly but the factory disappears.
I couldn't find any reason for this behaviour and need help.
Thanks in advance
With best regards
Sven

