Example #1
0
 /**
  * Instantiates and configures the renderer's helper manager
  *
  * @return ViewHelperManager
  */
 public function getHelperManager()
 {
     if ($this->helperManager) {
         return $this->helperManager;
     }
     $this->helperManager = new ViewHelperManager();
     // Setup additional helpers
     $map = array();
     if (isset($this->config['helper_map'])) {
         $map = $this->config['helper_map'];
     }
     if (!in_array('Zend\\Form\\View\\HelperConfiguration', $map)) {
         array_unshift($map, 'Zend\\Form\\View\\HelperConfiguration');
     }
     foreach ($map as $key => $service) {
         if ((!is_string($key) || is_numeric($key)) && class_exists($service)) {
             $config = new $service();
             if (!$config instanceof ConfigurationInterface) {
                 throw new Exception\RuntimeException(sprintf('Invalid helper configuration map provided; received "%s", expected class implementing %s', $service, 'Zend\\ServiceManager\\ConfigurationInterface'));
             }
             $config->configureServiceManager($this->helperManager);
             continue;
         }
         $this->helperManager->setInvokableClass($key, $service);
     }
     // Seed with service manager
     if ($this->services instanceof ServiceManager) {
         $this->helperManager->addPeeringServiceManager($this->services, ServiceManager::SCOPE_PARENT);
     }
     // Configure URL view helper with router
     $this->helperManager->setFactory('Zend\\View\\Helper\\Url', function ($sm) {
         $urlHelper = new \Zend\View\Helper\Url();
         $urlHelper->setRouter($sm->get('Router'));
         return $urlHelper;
     });
     $this->helperManager->setAlias('url', 'Zend\\View\\Helper\\Url');
     $config = $this->config;
     // Configure basePath view helper with base path from configuration, if available
     $this->helperManager->setFactory('Zend\\View\\Helper\\BasePath', function ($sm) use($config) {
         $basePathHelper = new \Zend\View\Helper\BasePath();
         if (isset($config['base_path'])) {
             $basePath = $config['base_path'];
         } else {
             $basePath = $sm->get('Request')->getBasePath();
         }
         $basePathHelper->setBasePath($basePath);
         return $basePathHelper;
     });
     $this->helperManager->setAlias('basepath', 'Zend\\View\\Helper\\BasePath');
     // Configure doctype view helper with doctype from configuration, if available
     $this->helperManager->setFactory('Zend\\View\\Helper\\Doctype', function ($sm) use($config) {
         $doctypeHelper = new \Zend\View\Helper\Doctype();
         if (isset($config['doctype'])) {
             $doctypeHelper->setDoctype($config['doctype']);
         }
         return $doctypeHelper;
     });
     $this->helperManager->setAlias('doctype', 'Zend\\View\\Helper\\Doctype');
     $this->services->setService('ViewHelperManager', $this->helperManager);
     $this->services->setAlias('ViewHelperBroker', 'ViewHelperManager');
     $this->services->setAlias('Zend\\View\\HelperPluginManager', 'ViewHelperManager');
     return $this->helperManager;
 }
Example #2
0
    /**
     * Instantiates and configures the renderer's helper broker
     * 
     * @return ViewHelperBroker
     */
    public function getHelperBroker()
    {
        if ($this->helperBroker) {
            return $this->helperBroker;
        }

        $this->helperBroker = new ViewHelperBroker();
        $this->helperBroker->setClassLoader($this->getHelperLoader());

        // Seed with service manager
        $this->helperBroker->setServiceLocator($this->services);

        // Configure URL view helper with router
        $this->services->setFactory('Zend\View\Helper\Url', function($sm) {
            $urlHelper = new \Zend\View\Helper\Url;
            $urlHelper->setRouter($sm->get('Router'));
            return $urlHelper;
        });

        $config = $this->config;

        // Configure basePath view helper with base path from configuration, if available
        $this->services->setFactory('Zend\View\Helper\BasePath', function($sm) use($config) {
            $basePathHelper = new \Zend\View\Helper\BasePath;
            if (isset($config['base_path'])) {
                $basePath = $config['base_path'];
            } else {
                $basePath = $sm->get('Request')->getBasePath();
            }
            $basePathHelper->setBasePath($basePath);
            return $basePathHelper;
        });

        // Configure doctype view helper with doctype from configuration, if available
        $this->services->setFactory('Zend\View\Helper\Doctype', function($sm) use($config) {
            $doctypeHelper = new \Zend\View\Helper\Doctype;
            if (isset($config['doctype'])) {
                $doctypeHelper->setDoctype($config['doctype']);
            }
            return $doctypeHelper;
        });

        $this->services->setService('ViewHelperBroker', $this->helperBroker);
        $this->services->setAlias('Zend\View\HelperBroker', 'ViewHelperBroker');

        return $this->helperBroker;
    }