Exemplo n.º 1
0
 protected function compileFileFull($file)
 {
     $tempFilePath = $this->tempFolder() . '/' . $file->subPathsPath() . $file->name() . ($this->config['compress'] ? '-c' : '') . '.' . $file->type();
     $dir = pathinfo($tempFilePath, PATHINFO_DIRNAME);
     if (!is_dir($dir)) {
         mkdir($dir, 0775, true);
     }
     $processor = new Processor\Processor($this);
     $processor->listFiles($file);
     # Check if file has changed to recompile it or not.
     if (is_file($tempFilePath)) {
         $recompile = false;
         $tempFileMTime = filemtime($tempFilePath);
         foreach ($processor->files() as $subFile) {
             if (filemtime($subFile->originalFilePath()) > $tempFileMTime) {
                 $recompile = true;
                 break;
             }
         }
     } else {
         $recompile = true;
     }
     if ($recompile) {
         $compiledFile = $processor->compileFiles();
         $compiledFile = $this->compressCompiledFile($file->type(), $compiledFile);
         # Cache compiled file.
         file_put_contents($tempFilePath, $compiledFile);
     }
     return ['file' => $file, 'tempFilePath' => $tempFilePath];
 }
Exemplo n.º 2
0
 protected function buildAssetTag($type, Closure $builder, $sources, array $options)
 {
     $sources = (array) $sources;
     $tags = [];
     if (isset($options['protocol'])) {
         $protocol = $options['protocol'];
         unset($options['protocol']);
     } else {
         $protocol = '';
     }
     if ($this->config['serve_static_assets']) {
         foreach ($sources as &$source) {
             $this->ensureAssetType($type, $source);
         }
         // if ($this->config['use_cache']) {
         // $key = 'asset-tags-' . crc32(implode($sources));
         // if ($tags = $this->getService('rails.cache')->read($key)) {
         // return $tags;
         // }
         // $tags = [];
         // }
         foreach ($sources as $source) {
             $this->appendAssetTag($source, $type, $builder, $options, false, $tags);
         }
         // if ($this->config['use_cache']) {
         // $this->getService('rails.cache')->write($key, implode("\n", $tags));
         // }
     } else {
         if ($this->config['assets']['concat']) {
             foreach ($sources as $source) {
                 $this->ensureAssetType($type, $source);
                 $this->compileAssetFile($source);
                 $this->appendAssetTag($source, $type, $builder, $options, false, $tags);
             }
         } else {
             $assets = $this->getService('assets');
             $processor = new AssetProcessor($assets);
             foreach ($sources as $source) {
                 $this->ensureAssetType($type, $source);
                 $file = $assets->findFile($source);
                 if (!$file) {
                     $this->compileAssetFile($source);
                     $this->appendAssetTag($source, $type, $builder, $options, true, $tags);
                     continue;
                 }
                 $processor->listFiles($file);
                 foreach ($processor->files() as $subFile) {
                     $this->compileAssetFile($subFile->logicalPath());
                     $this->appendAssetTag($subFile->url(), $type, $builder, $options, true, $tags);
                 }
             }
         }
     }
     return implode("\n", $tags);
 }