/** * {@inheritdoc} */ public function get($filename, $scope) { switch ($scope) { case 'global': $iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray(); $themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath(); if ($themeConfigFile && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))) { $iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($themeConfigFile)); } else { $designPath = $this->resolver->resolve(RulePool::TYPE_FILE, 'etc/view.xml', $this->area, $this->currentTheme); if (file_exists($designPath)) { try { $designDom = new \DOMDocument(); $designDom->load($designPath); $iterator[$designPath] = $designDom->saveXML(); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Could not read config file')); } } } break; default: $iterator = $this->iteratorFactory->create([]); break; } return $iterator; }
/** * @param bool $isEnabled * @param string $requested * @param string $alternative * @param string $expected * @param string $resolvedOriginal * @param string $resolvedAlternative * @return void * @dataProvider resolveDataProvider */ public function testResolve($isEnabled, $requested, $alternative, $expected, $resolvedOriginal, $resolvedAlternative) { $this->assetMinificationMock->expects($this->any())->method('isEnabled')->willReturn($isEnabled); $this->assetMinificationMock->expects($this->any())->method('addMinifiedSign')->with($requested)->willReturn($alternative); $this->resolverMock->expects($this->any())->method('resolve')->willReturnMap([['', $requested, null, null, null, null, $resolvedOriginal], ['', $alternative, null, null, null, null, $resolvedAlternative]]); $this->assertEquals($expected, $this->minification->resolve('', $requested)); }
/** * 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) { $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; }
public function testGetFile() { $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface'); $expected = 'some/file.ext'; $this->resolver->expects($this->once())->method('resolve')->with(RulePool::TYPE_TEMPLATE_FILE, 'file.ext', 'frontend', $theme, null, 'Magento_Module')->will($this->returnValue($expected)); $actual = $this->object->getFile('frontend', $theme, 'file.ext', 'Magento_Module'); $this->assertSame($expected, $actual); }
public function testResolveJsToNotFindMinifiedVersion() { $this->resolverMock ->expects($this->exactly(2)) ->method('resolve') ->willReturnMap( [ ['', 'test.js', null, null, null, null, '/var/test.js'], ['', 'test.min.js', null, null, null, null, false] ] ); $this->assetMinificationMock->expects($this->once()) ->method('isMinifiedFilename') ->willReturn(false); $this->assetMinificationMock->expects($this->once()) ->method('isEnabled') ->with('js') ->willReturn(true); $this->assetMinificationMock->expects($this->once()) ->method('addMinifiedSign') ->with('test.js') ->willReturn('test.min.js'); $this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js')); }
/** * Recursively add parent theme configs * * @param ThemeInterface $theme * @param array $iterator * @param int $index * @return array */ private function getParentConfigs(ThemeInterface $theme, array $iterator, $index = 0) { if ($theme->getParentTheme() && $theme->isPhysical()) { $parentDesignPath = $this->resolver->resolve(RulePool::TYPE_FILE, 'etc/view.xml', $this->area, $theme->getParentTheme()); $parentDom = new \DOMDocument(); $parentDom->load($parentDesignPath); $iterator[$index] = $parentDom->saveXML(); $iterator = $this->getParentConfigs($theme->getParentTheme(), $iterator, ++$index); } return $iterator; }
/** * 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; }
/** * Get existing file name, using fallback mechanism * * @param string $area * @param ThemeInterface $themeModel * @param string $file * @param string|null $module * @return string|bool */ public function getFile($area, ThemeInterface $themeModel, $file, $module = null) { return $this->resolver->resolve($this->getFallbackType(), $file, $area, $themeModel, null, $module); }