예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
 {
     $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     if (!$dir->isExist($resultAsset->getPath())) {
         $this->strategy->merge($assetsToMerge, $resultAsset);
     }
 }
예제 #2
0
 /**
  * Fill the properties by copying properties from original asset and adding '.min' inside them
  *
  * @return void
  */
 protected function fillPropertiesByOriginalAssetWithMin()
 {
     $this->file = $this->composeMinifiedName($this->originalAsset->getSourceFile());
     $this->path = $this->composeMinifiedName($this->originalAsset->getPath());
     $this->filePath = $this->composeMinifiedName($this->originalAsset->getFilePath());
     $this->context = $this->originalAsset->getContext();
     $this->url = $this->composeMinifiedName($this->originalAsset->getUrl());
 }
예제 #3
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);
 }
예제 #4
0
 /**
  * Process an asset before merging into resulting asset
  *
  * @param Asset\LocalInterface $item
  * @param Asset\LocalInterface $result
  * @param string $content
  * @return string
  */
 private function preProcessBeforeMerging(Asset\LocalInterface $item, Asset\LocalInterface $result, $content)
 {
     if ($result->getContentType() == 'css') {
         $from = $item->getPath();
         $to = $result->getPath();
         return $this->cssUrlResolver->relocateRelativeUrls($content, $from, $to);
     }
     return $content;
 }
예제 #5
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);
 }
예제 #6
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);
 }
예제 #7
0
 /**
  * Generate minified file and fill the properties to reference that file
  *
  * @return void
  */
 protected function fillPropertiesByMinifyingAsset()
 {
     $path = $this->originalAsset->getPath();
     $this->context = new \Magento\Framework\View\Asset\File\Context($this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_STATIC]), DirectoryList::STATIC_VIEW, self::CACHE_VIEW_REL . '/minified');
     $this->filePath = md5($path) . '_' . $this->composeMinifiedName(basename($path));
     $this->path = $this->context->getPath() . '/' . $this->filePath;
     $this->minify();
     $this->file = $this->staticViewDir->getAbsolutePath($this->path);
     $this->url = $this->context->getBaseUrl() . $this->path;
 }
예제 #8
0
 /**
  * @param LocalInterface $asset
  * @param string $origContent
  * @param string $origContentType
  */
 public function __construct(LocalInterface $asset, $origContent, $origContentType)
 {
     $this->asset = $asset;
     $this->origContent = $origContent;
     $this->content = $origContent;
     $this->origContentType = $origContentType;
     $this->contentType = $origContentType;
     $this->targetContentType = $asset->getContentType();
     $this->targetAssetPath = $asset->getPath();
 }
예제 #9
0
 /**
  * Convert module notation to a path relative to the specified asset
  *
  * For example, the asset is Foo_Bar/styles/style.css and it refers to Bar_Baz::images/logo.gif
  * (i.e. url(Bar_Baz::images/logo.gif))
  * The result will be ../../Bar_Baz/images/logo.gif
  *
  * @param Asset\LocalInterface $thisAsset
  * @param string $relatedFileId
  * @return string
  */
 public function convertModuleNotationToPath(Asset\LocalInterface $thisAsset, $relatedFileId)
 {
     if (false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) {
         return $relatedFileId;
     }
     $thisPath = $thisAsset->getPath();
     $relatedAsset = $this->assetRepo->createSimilar($relatedFileId, $thisAsset);
     $relatedPath = $relatedAsset->getPath();
     $offset = FileSystem::offsetPath($relatedPath, $thisPath);
     return FileSystem::normalizePath($offset . '/' . basename($relatedPath));
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
 {
     $sourceDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
     $mTime = null;
     /** @var \Magento\Framework\View\Asset\MergeableInterface $asset */
     foreach ($assetsToMerge as $asset) {
         $mTime .= $sourceDir->stat($sourceDir->getRelativePath($asset->getSourceFile()))['mtime'];
     }
     if (null === $mTime) {
         return;
         // nothing to merge
     }
     $dat = $resultAsset->getPath() . '.dat';
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     if (!$targetDir->isExist($dat) || strcmp($mTime, $targetDir->readFile($dat)) !== 0) {
         $this->strategy->merge($assetsToMerge, $resultAsset);
         $targetDir->writeFile($dat, $mTime);
     }
 }
예제 #11
0
파일: Source.php 프로젝트: koliaGI/magento2
 /**
  * Find asset file by simply appending its path to the directory in context
  *
  * @param LocalInterface $asset
  * @param \Magento\Framework\View\Asset\File\Context $context
  * @return string
  */
 private function findFile(LocalInterface $asset, \Magento\Framework\View\Asset\File\Context $context)
 {
     $dir = $this->filesystem->getDirectoryRead($context->getBaseDirType());
     Simple::assertFilePathFormat($asset->getFilePath());
     return $dir->getAbsolutePath($asset->getPath());
 }
예제 #12
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;
    }