Ejemplo n.º 1
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $dir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     $rootDir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $source = $rootDir->getRelativePath($asset->getSourceFile());
     $destination = $asset->getPath();
     return $rootDir->copyFile($source, $destination, $dir);
 }
Ejemplo n.º 2
0
 /**
  * Whether the strategy can be applied
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 public function isSupported(Asset\LocalInterface $asset)
 {
     $sourceParts = explode('/', $asset->getSourceFile());
     if (in_array(DirectoryList::TMP_MATERIALIZATION_DIR, $sourceParts)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $rootDir->getRelativePath($asset->getSourceFile());
     $destination = $asset->getPath();
     $strategy = $this->materializationStrategyFactory->create($asset);
     return $strategy->publishFile($rootDir, $targetDir, $source, $destination);
 }
Ejemplo n.º 4
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $fullSource = $asset->getSourceFile();
     $source = basename($fullSource);
     $sourceDir = $this->writeFactory->create(dirname($fullSource));
     $destination = $asset->getPath();
     $strategy = $this->materializationStrategyFactory->create($asset);
     return $strategy->publishFile($sourceDir, $targetDir, $source, $destination);
 }
Ejemplo n.º 5
0
 /**
  * Perform actual minification
  *
  * @return void
  */
 protected function minify()
 {
     $isExists = $this->staticViewDir->isExist($this->path);
     if (!$isExists) {
         $shouldMinify = true;
     } elseif ($this->strategy == self::FILE_EXISTS) {
         $shouldMinify = false;
     } else {
         $origlFile = $this->rootDir->getRelativePath($this->originalAsset->getSourceFile());
         $origMtime = $this->rootDir->stat($origlFile)['mtime'];
         $minMtime = $this->staticViewDir->stat($this->path)['mtime'];
         $shouldMinify = $origMtime != $minMtime;
     }
     if ($shouldMinify) {
         $content = $this->adapter->minify($this->originalAsset->getContent());
         $this->staticViewDir->writeFile($this->path, $content);
     }
 }
Ejemplo n.º 6
0
 /**
  * @param LocalInterface $asset
  * @return bool
  */
 protected function isAssetMinification(LocalInterface $asset)
 {
     $sourceFile = $asset->getSourceFile();
     if (in_array($asset->getFilePath(), $this->excluded)) {
         return false;
     }
     if ($this->assetConfig->isAssetMinification($asset->getContentType())) {
         if (strpos($sourceFile, '.min.') !== false) {
             $this->excluded[] = str_replace('.min.', '', $sourceFile);
             return true;
         }
         $extension = $asset->getContentType();
         $minAbsolutePath = str_replace($extension, "min.{$extension}", $sourceFile);
         if (file_exists($minAbsolutePath)) {
             return false;
         }
         return true;
     }
     if (strpos($sourceFile, '.min.') !== false) {
         $absolutePath = str_replace('.min.', '', $asset->getFilePath());
         if (file_exists($absolutePath)) {
             return false;
         }
     } else {
         $extension = $asset->getContentType();
         $this->excluded[] = str_replace($extension, "min.{$extension}", $asset->getFilePath());
     }
     return true;
 }
Ejemplo n.º 7
0
    /**
     * @param LocalInterface $asset
     * @return bool
     */
    protected function isAssetMinification(LocalInterface $asset)
    {
        $sourceFile = $asset->getSourceFile();
        $extension = $asset->getContentType();
        if (in_array($sourceFile, $this->excluded)) {
            return false;
        }

        if (strpos($sourceFile, '.min.') === false) {
            $info = pathinfo($asset->getPath());
            $assetMinifiedPath = $info['dirname'] . '/' . $info['filename'] . '.min.' . $info['extension'];
            if ($this->filesystem->getDirectoryRead(DirectoryList::APP)->isExist($assetMinifiedPath)) {
                $this->excluded[] = $sourceFile;
                return false;
            }
        } else {
            $this->excluded[] = $this->filesystem->getDirectoryRead(DirectoryList::APP)
                ->getAbsolutePath(str_replace(".min.$extension", ".$extension", $asset->getPath()));
        }

        return true;
    }