/**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @throws \Zend\View\Exception\RuntimeException
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var \ZfcTwig\moduleOptions $options */
     $options = $serviceLocator->get('ZfcTwig\\ModuleOptions');
     $managerOptions = $options->getHelperManager();
     $managerConfigs = isset($managerOptions['configs']) ? $managerOptions['configs'] : array();
     $baseManager = $serviceLocator->get('ViewHelperManager');
     $twigManager = new HelperPluginManager(new Config($managerOptions));
     $twigManager->addPeeringServiceManager($baseManager);
     foreach ($managerConfigs as $configClass) {
         if (is_string($configClass) && class_exists($configClass)) {
             $config = new $configClass();
             if (!$config instanceof ConfigInterface) {
                 throw new Exception\RuntimeException(sprintf('Invalid service manager configuration class provided; received "%s",
                             expected class implementing %s', $configClass, 'Zend\\ServiceManager\\ConfigInterface'));
             }
             $config->configureServiceManager($twigManager);
         }
     }
     return $twigManager;
 }
Ejemplo n.º 2
0
 /**
  * @param $string
  *
  * @return string
  */
 public function translate($string)
 {
     return $this->serviceLocator->get('translate')->__invoke($string);
 }