Пример #1
0
 /**
  * Retrieve files
  *
  * @param ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $namespace = $module = '*';
     $themePath = $theme->getFullPath();
     if (empty($themePath)) {
         return [];
     }
     $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
     if (!$themeAbsolutePath) {
         return [];
     }
     $themeDir = $this->readDirFactory->create($themeAbsolutePath);
     $searchPattern = "{$namespace}_{$module}/{$this->subDir}{$filePath}";
     $files = $themeDir->search($searchPattern);
     $result = [];
     $pattern = "#(?<moduleName>[^/]+)/{$this->subDir}" . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "\$#i";
     foreach ($files as $file) {
         $filename = $themeDir->getAbsolutePath($file);
         if (!preg_match($pattern, $filename, $matches)) {
             continue;
         }
         $result[] = $this->fileFactory->create($filename, $matches['moduleName']);
     }
     return $result;
 }
Пример #2
0
 /**
  * Retrieve files
  *
  * @param ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $namespace = $module = '*';
     $themePath = $theme->getFullPath();
     if (empty($themePath)) {
         return [];
     }
     $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
     if (!$themeAbsolutePath) {
         return [];
     }
     $themeDir = $this->readDirFactory->create($themeAbsolutePath);
     $files = $themeDir->search("{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}");
     if (empty($files)) {
         return [];
     }
     $themes = [];
     $currentTheme = $theme;
     while ($currentTheme = $currentTheme->getParentTheme()) {
         $themes[$currentTheme->getCode()] = $currentTheme;
     }
     $result = [];
     $pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "\$#i";
     foreach ($files as $file) {
         $filename = $themeDir->getAbsolutePath($file);
         if (!preg_match($pattern, $filename, $matches)) {
             continue;
         }
         $moduleFull = $matches['module'];
         $ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName'];
         if (!isset($themes[$ancestorThemeCode])) {
             throw new LocalizedException(new \Magento\Framework\Phrase("Trying to override modular view file '%1' for theme '%2', which is not ancestor of theme '%3'", [$filename, $ancestorThemeCode, $theme->getCode()]));
         }
         $result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]);
     }
     return $result;
 }
Пример #3
0
 /**
  * @param string $path
  * @param string $expectedPattern
  *
  * @dataProvider translatePatternFromGlobDataProvider
  */
 public function testTranslatePatternFromGlob($path, $expectedPattern)
 {
     $this->assertEquals($expectedPattern, $this->pathPatternHelper->translatePatternFromGlob($path));
 }