예제 #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
 /**
  * Propagate parameters necessary for modular rule basing on module_name parameter
  *
  * @param array $params
  * @return array
  * @throws \InvalidArgumentException
  */
 public function getPatternDirs(array $params)
 {
     if (!array_key_exists('module_name', $params)) {
         throw new \InvalidArgumentException('Required parameter "module_name" is not specified.');
     }
     $params['module_dir'] = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $params['module_name']);
     return $this->rule->getPatternDirs($params);
 }
예제 #3
0
 /**
  * Get directory where themes files are stored
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return string|null
  */
 public function getThemeFilesPath(\Magento\Framework\View\Design\ThemeInterface $theme)
 {
     $path = null;
     if ($theme->getFullPath()) {
         $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $theme->getFullPath());
     }
     return $path;
 }
 /**
  * Get theme by path key
  *
  * @param string $key
  * @return ThemePackage
  * @throws \UnexpectedValueException
  */
 public function getTheme($key)
 {
     $themePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $key);
     if (empty($themePath)) {
         throw new \UnexpectedValueException("No theme registered with name '{$key}'");
     }
     return $this->factory->create($key, $themePath);
 }
예제 #5
0
 /**
  * Retrieve full path to a directory of certain type within a module
  *
  * @param string $moduleName Fully-qualified module name
  * @param string $type Type of module's directory to retrieve
  * @return string
  * @throws \InvalidArgumentException
  */
 public function getDir($moduleName, $type = '')
 {
     $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
     if ($type) {
         if (!in_array($type, [self::MODULE_ETC_DIR, self::MODULE_I18N_DIR, self::MODULE_VIEW_DIR, self::MODULE_CONTROLLER_DIR])) {
             throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
         }
         $path .= '/' . $type;
     }
     return $path;
 }
예제 #6
0
 /**
  * Retrieve files
  *
  * @param ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $list = $this->fileListFactory->create('Magento\\Framework\\Css\\PreProcessor\\File\\FileList\\Collator');
     $files = $this->libraryDirectory->search($filePath);
     $list->add($this->createFiles($this->libraryDirectory, $theme, $files));
     foreach ($theme->getInheritedThemes() as $currentTheme) {
         $themeFullPath = $currentTheme->getFullPath();
         $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themeFullPath);
         if (empty($path)) {
             continue;
         }
         $directoryRead = $this->readFactory->create($path);
         $foundFiles = $directoryRead->search("web/{$filePath}");
         $list->replace($this->createFiles($directoryRead, $theme, $foundFiles));
     }
     return $list->getAll();
 }
예제 #7
0
 /**
  * Propagate an underlying fallback rule to every theme in a hierarchy: parent, grandparent, etc.
  *
  * @param array $params
  * @return array
  * @throws \InvalidArgumentException
  */
 public function getPatternDirs(array $params)
 {
     if (!array_key_exists('theme', $params) || !$params['theme'] instanceof ThemeInterface) {
         throw new \InvalidArgumentException('Parameter "theme" should be specified and should implement the theme interface.');
     }
     $result = [];
     /** @var $theme ThemeInterface */
     $theme = $params['theme'];
     unset($params['theme']);
     while ($theme) {
         if ($theme->getFullPath()) {
             $params['theme_dir'] = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $theme->getFullPath());
             $result = array_merge($result, $this->rule->getPatternDirs($params));
         }
         $theme = $theme->getParentTheme();
     }
     return $result;
 }
예제 #8
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;
 }