/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $result = []; $namespace = $module = '*'; $sharedFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/base/{$this->subDir}{$filePath}"); $filePathPtn = strtr(preg_quote($filePath), ['\\*' => '[^/]+']); $pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/base/{$this->subDir}" . $filePathPtn . "\$#i"; foreach ($sharedFiles as $file) { $filename = $this->modulesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = "{$matches['namespace']}_{$matches['module']}"; $result[] = $this->fileFactory->create($filename, $moduleFull, null, true); } $area = $theme->getData('area'); $themeFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/{$area}/{$this->subDir}{$filePath}"); $pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/{$area}/{$this->subDir}" . $filePathPtn . "\$#i"; foreach ($themeFiles as $file) { $filename = $this->modulesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = "{$matches['namespace']}_{$matches['module']}"; $result[] = $this->fileFactory->create($filename, $moduleFull); } return $result; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] * @throws \Magento\Framework\Exception */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); $searchPattern = "{$themePath}/{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}"; $files = $this->themesDirectory->search($searchPattern); if (empty($files)) { return []; } $themes = []; $currentTheme = $theme; while ($currentTheme = $currentTheme->getParentTheme()) { $themes[$currentTheme->getCode()] = $currentTheme; } $result = []; $pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . strtr(preg_quote($filePath), ['\\*' => '[^/]+']) . "\$#i"; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = $matches['module']; $ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName']; if (!isset($themes[$ancestorThemeCode])) { throw new Exception(sprintf("Trying to override modular view file '%s' for theme '%s', which is not ancestor of theme '%s'", $filename, $ancestorThemeCode, $theme->getCode())); } $result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]); } return $result; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function get($filename, $scope) { $configPaths = $this->configDirectory->search('{*' . $filename . ',*/*' . $filename . '}'); $configAbsolutePaths = []; foreach ($configPaths as $configPath) { $configAbsolutePaths[] = $this->configDirectory->getAbsolutePath($configPath); } return $this->iteratorFactory->create($configAbsolutePaths); }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $themePath = $theme->getFullPath(); $files = $this->themesDirectory->search("{$themePath}/{$this->subDir}{$filePath}"); $result = []; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); $result[] = $this->fileFactory->create($filename, null, $theme); } return $result; }
/** * 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->_string->upperCaseWords($moduleName, '_', '/'); if ($type) { if (!in_array($type, array('etc', 'sql', 'data', 'i18n', 'view', 'Controller'))) { throw new \InvalidArgumentException("Directory type '{$type}' is not recognized."); } $path .= '/' . $type; } $result = $this->_modulesDirectory->getAbsolutePath($path); return $result; }
/** * 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 = '') { if (null === ($path = $this->moduleRegistry->getModulePath($moduleName))) { $relativePath = $this->_string->upperCaseWords($moduleName, '_', '/'); $path = $this->_modulesDirectory->getAbsolutePath($relativePath); } 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; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); $files = $this->themesDirectory->search("{$themePath}/{$namespace}_{$module}/{$this->subDir}{$filePath}"); $result = array(); $pattern = "#/(?<moduleName>[^/]+)/{$this->subDir}" . strtr(preg_quote($filePath), array('\\*' => '[^/]+')) . "\$#i"; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $result[] = $this->fileFactory->create($filename, $matches['moduleName'], $theme); } return $result; }
/** * Perform necessary preprocessing and materialization when the specified asset is requested * * Returns an array of two elements: * - directory where the file is supposed to be found * - relative path to the file * * returns false if source file was not found * * @param LocalInterface $asset * @return array|bool */ private function preProcess(LocalInterface $asset) { $sourceFile = $this->findSourceFile($asset); $dir = $this->rootDir->getAbsolutePath(); $path = ''; if ($sourceFile) { $path = basename($sourceFile); $dir = dirname($sourceFile); } $chain = $this->createChain($asset, $dir, $path); $this->preProcessorPool->process($chain); $chain->assertValid(); if ($chain->isChanged()) { $dir = $this->varDir->getAbsolutePath(); $path = DirectoryList::TMP_MATERIALIZATION_DIR . '/source/' . $chain->getTargetAssetPath(); $this->varDir->writeFile($path, $chain->getContent()); } if (empty($path)) { $result = false; } else { $result = [$dir, $path]; } return $result; }
/** * Get layout files from modules, theme with ancestors and library * * @param ThemeInterface $theme * @param string $filePath * @throws \InvalidArgumentException * @return \Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { if (empty($filePath)) { throw new \InvalidArgumentException('File path must be specified'); } $files = []; if ($this->libDirectory->isExist($filePath)) { $filename = $this->libDirectory->getAbsolutePath($filePath); $files[] = $this->fileFactory->create($filename); } $files = array_merge($files, $this->baseFiles->getFiles($theme, $filePath)); foreach ($theme->getInheritedThemes() as $currentTheme) { $files = array_merge($files, $this->themeModularFiles->getFiles($currentTheme, $filePath)); $files = array_merge($files, $this->themeFiles->getFiles($currentTheme, $filePath)); } return $files; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function get($filename, $scope) { $moduleDir = $this->modulesDirectory->getAbsolutePath(); $configDir = $this->configDirectory->getAbsolutePath(); $mageScopePath = $moduleDir . '/Magento'; $output = array('base' => array(), 'mage' => array(), 'custom' => array()); $files = glob($moduleDir . '*/*/etc/module.xml'); foreach ($files as $file) { $scope = strpos($file, $mageScopePath) === 0 ? 'mage' : 'custom'; $output[$scope][] = $this->rootDirectory->getRelativePath($file); } $files = glob($configDir . '*/module.xml'); foreach ($files as $file) { $output['base'][] = $this->rootDirectory->getRelativePath($file); } return $this->iteratorFactory->create($this->rootDirectory, array_merge($output['mage'], $output['custom'], $output['base'])); }
/** * @param ReadInterface $reader * @param ThemeInterface $theme * @param array $files * @return array */ protected function createFiles(ReadInterface $reader, ThemeInterface $theme, $files) { $result = []; foreach ($files as $file) { $filename = $reader->getAbsolutePath($file); $result[] = $this->fileFactory->create($filename, false, $theme); } return $result; }
/** * 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; }
/** * {@inheritdoc} */ public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { self::assertFilePathFormat($file); $themePath = $theme ? $theme->getThemePath() : ''; $path = $this->cache->getFromCache($type, $file, $area, $themePath, $locale, $module); if (false !== $path) { $path = $path ? $this->rootDirectory->getAbsolutePath($path) : false; } else { $params = ['area' => $area, 'theme' => $theme, 'locale' => $locale]; foreach ($params as $key => $param) { if ($param === null) { unset($params[$key]); } } if (!empty($module)) { list($params['namespace'], $params['module']) = explode('_', $module, 2); } $path = $this->resolveFile($this->rulePool->getRule($type), $file, $params); $cachedValue = $path ? $this->rootDirectory->getRelativePath($path) : ''; $this->cache->saveToCache($cachedValue, $type, $file, $area, $themePath, $locale, $module); } return $path; }
/** * Quote item to order item copy process * * @return $this */ public function copyQuoteToOrder() { $quoteOption = $this->getConfigurationItemOption(); try { $value = unserialize($quoteOption->getValue()); if (!isset($value['quote_path'])) { throw new \Exception(); } $quotePath = $value['quote_path']; $orderPath = $value['order_path']; if (!$this->_rootDirectory->isFile($quotePath) || !$this->_rootDirectory->isReadable($quotePath)) { throw new \Exception(); } $this->_coreFileStorageDatabase->copyFile($this->_rootDirectory->getAbsolutePath($quotePath), $this->_rootDirectory->getAbsolutePath($orderPath)); } catch (\Exception $e) { return $this; } return $this; }
/** * Retrieve available Data install/upgrade files for current module * * @param string $actionType * @param string $fromVersion * @param string $toVersion * @return array */ protected function _getAvailableDataFiles($actionType, $fromVersion, $toVersion) { $modName = (string) $this->_moduleConfig['name']; $files = []; $filesDir = $this->_modulesReader->getModuleDir('data', $modName) . '/' . $this->_resourceName; $modulesDirPath = $this->modulesDir->getRelativePath($filesDir); if ($this->modulesDir->isDirectory($modulesDirPath) && $this->modulesDir->isReadable($modulesDirPath)) { $regExp = sprintf('#%s-(.*)\\.php$#i', $actionType); foreach ($this->modulesDir->read($modulesDirPath) as $file) { $matches = []; if (preg_match($regExp, $file, $matches)) { $files[$matches[1]] = $this->modulesDir->getAbsolutePath($file); } } } if (empty($files)) { return []; } return $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $files); }
/** * Get directory path for preview image * * @return string */ public function getImagePreviewDirectory() { return $this->mediaDirectory->getAbsolutePath(self::PREVIEW_DIRECTORY_PATH); }
/** * Set font as italic * * @param \Zend_Pdf_Page $object * @param int $size * @return \Zend_Pdf_Resource_Font */ protected function _setFontItalic($object, $size = 7) { $font = \Zend_Pdf_Font::fontWithPath($this->_rootDirectory->getAbsolutePath('lib/internal/LinLibertineFont/LinLibertine_It-2.8.2.ttf')); $object->setFont($font, $size); return $font; }