Beispiel #1
0
 /**
  * Process css cache items
  *
  * @param array $cacheItems
  * @return array
  */
 protected function processCssCacheItems(array $cacheItems)
 {
     $items = [];
     // process cache items
     foreach ($cacheItems as $media => $conditions) {
         foreach ($conditions as $condition => $files) {
             $filesHash = null;
             // get files hash
             foreach ($files as $file) {
                 $filesHash .= $file->href;
             }
             // check files hash
             $cacheFile = md5($filesHash . $condition . $media) . $this->cacheCssFileExtension;
             $layoutCachePath = LayoutService::getLayoutCachePath();
             // generate new cache file
             if (!file_exists($layoutCachePath . $cacheFile)) {
                 $content = null;
                 // get file content
                 foreach ($files as $file) {
                     // check the file sheme
                     $fileInfo = parse_url($file->href);
                     // add absolute path to file
                     if (empty($fileInfo['scheme'])) {
                         $file->path = APPLICATION_PUBLIC . '/' . $file->href;
                     }
                     $basePath = empty($fileInfo['scheme']) ? $this->view->basePath() . '/' . dirname($file->href) : dirname($file->href);
                     // get file content
                     if (false !== ($result = $this->processCssContent(isset($file->path) ? $file->path : $file->href, $basePath))) {
                         $content .= $result;
                     }
                 }
                 $cacheFilePath = $layoutCachePath . $cacheFile;
                 // write cache
                 $this->genCacheFile($cacheFilePath, $content);
                 // check css cache gzip status
                 if ($this->isCssCacheGzipEnabled()) {
                     $this->gzipContent($cacheFilePath, $content);
                 }
             }
             // get new url
             $file->href = LayoutService::getLayoutCacheDir() . '/' . $cacheFile;
             $items[] = $this->itemToString($file);
         }
     }
     return $items;
 }
 /**
  * Process cache items
  *
  * @param array $cacheItems
  * @param  string $indent      String to add before the item
  * @param  string $escapeStart Starting sequence
  * @param  string $escapeEnd   Ending sequence
  * @return array
  */
 protected function processCacheItems(array $cacheItems, $indent, $escapeStart, $escapeEnd)
 {
     $items = [];
     // process cache items
     foreach ($cacheItems as $scriptType => $conditions) {
         foreach ($conditions as $condition => $scripts) {
             $scriptsHash = null;
             // get scripts hash
             foreach ($scripts as $script) {
                 if (!empty($script->source)) {
                     $scriptsHash .= $script->source;
                 } else {
                     // check the file sheme
                     $fileInfo = parse_url($script->attributes['src']);
                     // add absolute path to file
                     if (empty($fileInfo['scheme'])) {
                         $script->attributes['src'] = APPLICATION_PUBLIC . '/' . $script->attributes['src'];
                     }
                     $scriptsHash .= $script->attributes['src'];
                 }
             }
             // check scripts hash
             $cacheFile = md5($scriptsHash . $condition . $scriptType) . $this->cacheFileExtension;
             $layoutCachePath = LayoutService::getLayoutCachePath('js');
             // generate new cache file
             if (!file_exists($layoutCachePath . $cacheFile)) {
                 $content = null;
                 foreach ($scripts as $script) {
                     if (!empty($script->source)) {
                         $content .= $script->source . PHP_EOL;
                     } else {
                         if (!empty($script->attributes['src'])) {
                             // get file content
                             if (false !== ($result = file_get_contents($script->attributes['src']))) {
                                 $content .= $result . PHP_EOL;
                             }
                         }
                     }
                 }
                 $cacheFilePath = $layoutCachePath . $cacheFile;
                 // write cache
                 $this->genCacheFile($cacheFilePath, $content);
                 // check cache gzip status
                 if ($this->isCacheGzipEnabled()) {
                     $this->gzipContent($cacheFilePath, $content);
                 }
             }
             $itemInfo = new stdClass();
             $itemInfo->type = $scriptType;
             $itemInfo->attributes['conditional'] = $condition;
             $itemInfo->attributes['src'] = LayoutService::getLayoutCacheDir('js') . '/' . $cacheFile;
             $items[] = $this->itemToString($itemInfo, $indent, $escapeStart, $escapeEnd);
         }
     }
     return $items;
 }