Beispiel #1
0
 /**
  * Retrieve the filesystem path to a view script
  *
  * @param  string $name
  * @param  null|Renderer $renderer
  * @throws \Zend\View\Exception\DomainException
  * @return string
  */
 public function resolve($name, Renderer $renderer = null)
 {
     if (!self::$currentLayoutId) {
         $activeLayouts = LayoutService::getCurrentLayouts();
         self::$currentLayoutId = end($activeLayouts)['name'];
     }
     // generate a cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_TEMPLATE_PATH, [$name, $renderer, self::$currentLayoutId]);
     // check data in cache
     if (null === ($templatePath = $this->dynamicCacheInstance->getItem($cacheName))) {
         if (false !== ($templatePath = parent::resolve($name, $renderer))) {
             // save data in cache
             $this->dynamicCacheInstance->setItem($cacheName, $templatePath);
         }
     }
     return $templatePath;
 }
Beispiel #2
0
 /**
  * Get resource's url
  *
  * @param string $fileName
  * @param string $type (possible values are: js, css and image)
  * @param string $module
  * @return string|false
  */
 public function __invoke($fileName, $type = 'js', $module = self::DEFAULT_MODULE)
 {
     if (!self::$currentLayoutId) {
         $activeLayouts = LayoutService::getCurrentLayouts();
         self::$currentLayoutId = end($activeLayouts)['name'];
     }
     // generate a dynamicCacheInstance name
     $dynamicCacheInstanceName = CacheUtility::getCacheName(self::CACHE_RESOURCE_PATH, [$fileName, $type, $module, self::$currentLayoutId]);
     if (null === ($resourcePath = $this->dynamicCacheInstance->getItem($dynamicCacheInstanceName))) {
         $baseResourcePath = $this->layoutPath;
         // get a resource url
         foreach ($this->layouts as $layout) {
             $checkResourcePath = $baseResourcePath . $layout['name'] . '/' . $module . '/' . $type . '/' . $fileName;
             if (file_exists($checkResourcePath)) {
                 $resourcePath = $this->layoutDir . '/' . $layout['name'] . '/' . $module . '/' . $type . '/' . $fileName;
                 // save data in dynamicCacheInstance
                 $this->dynamicCacheInstance->setItem($dynamicCacheInstanceName, $resourcePath);
             }
         }
     }
     return $resourcePath ? $resourcePath : false;
 }
Beispiel #3
0
 /**
  * Init view helpers
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return ['invokables' => ['layoutHeadLink' => 'Layout\\View\\Helper\\LayoutHeadLink', 'layoutHeadScript' => 'Layout\\View\\Helper\\LayoutHeadScript'], 'factories' => ['layoutAsset' => function () {
         $cache = $this->serviceLocator->get('Application\\Cache\\Dynamic');
         return new \Layout\View\Helper\LayoutAsset($cache, LayoutService::getLayoutPath(), LayoutService::getCurrentLayouts(), LayoutService::getLayoutDir());
     }, 'layoutList' => function () {
         $layouts = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Layout\\Model\\LayoutBase');
         return new \Layout\View\Helper\LayoutList($layouts->getAllInstalledLayouts(), LayoutService::getCurrentLayouts());
     }]];
 }