Looking for a way to define a view helper via configuration. That helper should be created via callback factory and have a dependency injected in constructor, as per documentation here: Registering Helpers
So there we go with a helper itself:
class Locale extends AbstractHelper
{
protected $localeService;
public function __construct(LocaleService $localeService = null) {
$this->localeService = $localeService;
}
public function __invoke() {
return $this->localeService->getCurrentLocale();
}
}
An it's being defined in configuration like this:
//view helpers
'view_helpers' => array(
'invokables' => array(),
'factories' => array(
'currentLocale' => function($pluginManager) {
return new \ShiftKernel\Locale\ViewHelper\Locale(
$pluginManager->get('ShiftKernel\Locale\LocaleService')
);
},
),
),
Whenever I now use it just explodes with an exception:
Fatal error: Call to undefined method Zend\ServiceManager\ServiceManager::setView() in /_www/hosts/zend2/zend2/vendor/zendframework/zendframework/Zend/View/HelperPluginManager.php on line 135
Am I wrong in how I instantiate helper dependency? Isn't it possible to get() the service from PuginManager (since it's a ServiceManager by itself)? Will I need to define dependency service as factory in plugin managers factories? Is it at all possible to do what I'm trying to achieve?