Пример #1
0
 /**
  * Get path of file after using fallback rules
  *
  * @param string $type
  * @param string $file
  * @param string|null $area
  * @param ThemeInterface|null $theme
  * @param string|null $locale
  * @param string|null $module
  * @return string|false
  */
 public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null)
 {
     $file = $this->minification->addMinifiedSign($file);
     $path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module);
     if (!$path && $file != ($newFile = $this->minification->removeMinifiedSign($file))) {
         $path = $this->fallback->resolve($type, $newFile, $area, $theme, $locale, $module);
     }
     return $path;
 }
Пример #2
0
 /**
  * @param array $types
  * @return void
  */
 protected function save($types)
 {
     $dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $bundlePath = '';
     foreach ($types as $parts) {
         /** @var FallbackContext $context */
         $context = reset(reset($parts)['assets'])->getContext();
         $bundlePath = empty($bundlePath) ? $context->getPath() . Manager::BUNDLE_PATH : $bundlePath;
         $this->fillContent($parts, $context);
     }
     $this->content[max(0, count($this->content) - 1)] .= $this->getInitJs();
     foreach ($this->content as $partIndex => $content) {
         $dir->writeFile($this->minification->addMinifiedSign($bundlePath . $partIndex . '.js'), $content);
     }
 }
Пример #3
0
    /**
     * Get path of file after using fallback rules
     *
     * @param string $type
     * @param string $file
     * @param string|null $area
     * @param ThemeInterface|null $theme
     * @param string|null $locale
     * @param string|null $module
     * @return string|false
     */
    private function resolveJsMinification(
        $type,
        $file,
        $area = null,
        ThemeInterface $theme = null,
        $locale = null,
        $module = null
    ) {
        $path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module);

        /**
         * Minified version as priority one
         */
        if ($path && $this->minification->isMinifiedFilename($path)) {
            return $path;
        }

        /**
         * If minification is disabled - return already found path
         */
        if (!$this->minification->isEnabled('js')) {
            return $path;
        }

        /**
         * Try to find minified version of file,
         * or return already found path
         */
        return $this->fallback->resolve(
            $type,
            $this->minification->addMinifiedSign($file),
            $area,
            $theme,
            $locale,
            $module
        ) ?: $path;
    }
 /**
  * @param string $filename
  * @param bool $isEnabled
  * @param string $expected
  * @dataProvider addMinifiedSignDataProvider
  */
 public function testAddMinifiedSign($filename, $isEnabled, $expected)
 {
     $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->willReturn($isEnabled);
     $this->appStateMock->expects($this->any())->method('getMode')->willReturn(State::MODE_DEFAULT);
     $this->assertEquals($expected, $this->minification->addMinifiedSign($filename));
 }
Пример #5
0
 /**
  * @return string
  */
 protected function getConfigFileName()
 {
     return $this->minification->addMinifiedSign(self::CONFIG_FILE_NAME);
 }