/**
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  * @param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator
  * @return \BoilerAppMessenger\Media\Mail\MailMessageRenderer
  */
 public function createService(\Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator)
 {
     $oMailMessageRenderer = new \BoilerAppMessenger\Media\Mail\MailMessageRenderer();
     //Template map
     $aConfiguration = $oServiceLocator->get('Config');
     if (isset($aConfiguration['medias'][\BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA])) {
         $aConfiguration = $aConfiguration['medias'][\BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA];
         if (isset($aConfiguration['template_map'])) {
             $oMailMessageRenderer->setTemplateMap($aConfiguration['template_map']);
         }
         //Templating service
         if (class_exists('TreeLayoutStack\\TemplatingService')) {
             $oMailMessageRenderer->setTemplatingService(\TreeLayoutStack\TemplatingService::factory(isset($aConfiguration['tree_layout_stack']) ? $aConfiguration['tree_layout_stack'] : array()));
         }
     }
     //AssetsBundle service
     if ($oServiceLocator->has('AssetsBundleService')) {
         $oMailMessageRenderer->setAssetsBundleService($oServiceLocator->get('AssetsBundleService'));
     }
     //StyleInliner service
     if ($oServiceLocator->has('StyleInlinerService')) {
         $oMailMessageRenderer->setStyleInlinerService($oServiceLocator->get('StyleInlinerService'));
     }
     //Translator
     if ($oServiceLocator->has('translator')) {
         $oTranslateHelper = new \Zend\I18n\View\Helper\Translate();
         $oMailMessageRenderer->getHelperPluginManager()->setService('translate', $oTranslateHelper->setTranslator($oServiceLocator->get('translator'))->setTranslatorEnabled(true));
     }
     //Router
     if ($oServiceLocator->has('router')) {
         $oUrlHelper = new \Zend\View\Helper\Url();
         $oMailMessageRenderer->getHelperPluginManager()->setService('url', $oUrlHelper->setRouter($oServiceLocator->get('router')));
     }
     return $oMailMessageRenderer;
 }
Exemplo n.º 2
0
 /**
  * Constructs an url for a menu item that may be used in the template.
  *
  * @param array $data menu item configuration
  *
  * @return string
  */
 public function getMenuItemUrl(array $data)
 {
     if (!$data['route']) {
         return $data['url'];
     }
     if (isset($data['routeParams'])) {
         return $this->urlHelper->__invoke($data['url'], $data['routeParams']);
     } else {
         return $this->urlHelper->__invoke($data['url']);
     }
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Internal function for parsing menu configuration.
  *
  * @param string $lng Language code
  *
  * @return void
  */
 protected function parseMenuConfig($lng)
 {
     $translator = $this->getView()->plugin('translate');
     $parseUrl = function ($url) {
         $url = trim($url);
         $data = [];
         if (strpos($url, ',') !== false) {
             list($url, $target) = explode(',', $url, 2);
             $url = trim($url);
             $data['target'] = trim($target);
         }
         if (preg_match('/^(http|https):\\/\\//', $url)) {
             // external url
             $data['url'] = $url;
             $data['route'] = false;
             return $data;
         }
         $data['route'] = true;
         $needle = 'content-';
         if (($pos = strpos($url, $needle)) === 0) {
             // Content pages do not have static routes, so we
             // need to add required route parameters for url view helper.
             $page = substr($url, $pos + strlen($needle));
             $data['routeParams'] = [];
             $data['routeParams']['page'] = $page;
             $url = 'content-page';
         }
         $data['url'] = $url;
         return $data;
     };
     $this->menuItems = [];
     foreach ($this->config as $menuKey => $items) {
         if ($menuKey === 'Parent_Config') {
             continue;
         }
         if (!count($items)) {
             continue;
         }
         $item = ['label' => "menu_{$menuKey}"];
         $desc = 'menu_' . $menuKey . '_desc';
         if ($translator->translate($desc, null, false) !== false) {
             $item['desc'] = $desc;
         }
         $options = [];
         foreach ($items as $itemKey => $action) {
             if (!$action) {
                 continue;
             }
             if (!is_string($action)) {
                 if (!isset($action[$lng])) {
                     continue;
                 } else {
                     $action = $action[$lng];
                 }
             }
             $option = array_merge(['label' => "menu_{$itemKey}"], $parseUrl($action));
             if ($option['route']) {
                 if (strpos('metalib-', $option['url']) === 0) {
                     if (!$this->metaLibHelper->isAvailable()) {
                         continue;
                     }
                 }
                 if (strpos('primo-', $option['url']) === 0) {
                     if (!$this->primoHelper->isAvailable()) {
                         continue;
                     }
                 }
                 if ($option['url'] === 'browse-database' && !$this->browseHelper->isAvailable('Database')) {
                     continue;
                 }
                 if ($option['url'] === 'browse-journal' && !$this->browseHelper->isAvailable('Journal')) {
                     continue;
                 }
             }
             $desc = 'menu_' . $itemKey . '_desc';
             if ($translator->translate($desc, null, false) !== false) {
                 $option['desc'] = $desc;
             }
             $options[] = $option;
         }
         if (empty($options)) {
             continue;
         } else {
             $item['items'] = $options;
             $this->menuItems[] = $item;
         }
     }
 }
Exemplo n.º 5
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;
    }