Пример #1
0
 /**
  * {@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;
 }
Пример #2
0
 /**
  * Read Magento updater application jobs queue as a JSON string.
  *
  * @return string Queue file content (valid JSON string)
  * @throws \RuntimeException
  */
 public function read()
 {
     $queue = '';
     if (!$this->reader->isExist($this->queueFileBasename)) {
         return $queue;
     }
     $queueFileContent = $this->reader->readFile($this->queueFileBasename);
     if ($queueFileContent) {
         json_decode($queueFileContent);
         if (json_last_error() !== JSON_ERROR_NONE) {
             throw new \RuntimeException(sprintf('Content of "%s" must be a valid JSON.', $this->queueFileBasename));
         }
         $queue = $queueFileContent;
     }
     return $queue;
 }
Пример #3
0
    /**
     * Render view config object for current package and theme
     *
     * @param array $params
     * @return \Magento\Framework\Config\View
     */
    public function getViewConfig(array $params = [])
    {
        $this->assetRepo->updateDesignParams($params);
        /** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
        $currentTheme = $params['themeModel'];
        $key = $currentTheme->getCode();
        if (isset($this->viewConfigs[$key])) {
            return $this->viewConfigs[$key];
        }

        $configFiles = $this->moduleReader->getConfigurationFiles(basename($this->filename))->toArray();
        $themeConfigFile = $currentTheme->getCustomization()->getCustomViewConfigPath();
        if (empty($themeConfigFile)
            || !$this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
        ) {
            $themeConfigFile = $this->viewFileSystem->getFilename($this->filename, $params);
        }
        if ($themeConfigFile
            && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
        ) {
            $configFiles[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile(
                $this->rootDirectory->getRelativePath($themeConfigFile)
            );
        }
        $config = $this->viewFactory->create($configFiles);

        $this->viewConfigs[$key] = $config;
        return $config;
    }
Пример #4
0
 /**
  * Checks existence of composer.lock and returns its contents
  *
  * @return array
  * @throws \Exception
  */
 private function getComposerInfo()
 {
     if (!$this->rootDir->isExist('composer.lock')) {
         throw new \Exception('Cannot read \'composer.lock\' file');
     }
     return json_decode($this->rootDir->readFile('composer.lock'), true);
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * Get path of file after using fallback rules
  *
  * @param RuleInterface $fallbackRule
  * @param string $file
  * @param array $params
  * @return string|bool
  */
 protected function resolveFile(RuleInterface $fallbackRule, $file, array $params = [])
 {
     foreach ($fallbackRule->getPatternDirs($params) as $dir) {
         $path = "{$dir}/{$file}";
         if ($this->rootDirectory->isExist($this->rootDirectory->getRelativePath($path))) {
             return $path;
         }
     }
     return false;
 }
Пример #7
0
 /**
  * Process additional data before save config
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if (is_array($value) && !empty($value['delete'])) {
         $this->setValue('');
         $this->_certFactory->create()->loadByWebsite($this->getScopeId())->delete();
     }
     if (!isset($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'])) {
         return $this;
     }
     $tmpPath = $this->_tmpDirectory->getRelativePath($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']);
     if ($tmpPath && $this->_tmpDirectory->isExist($tmpPath)) {
         if (!$this->_tmpDirectory->stat($tmpPath)['size']) {
             throw new \Magento\Framework\Model\Exception(__('The PayPal certificate file is empty.'));
         }
         $this->setValue($_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value']);
         $content = $this->_encryptor->encrypt($this->_tmpDirectory->readFile($tmpPath));
         $this->_certFactory->create()->loadByWebsite($this->getScopeId())->setContent($content)->save();
     }
     return $this;
 }
Пример #8
0
 /**
  * Get the list of files and directory paths from magento-base extra/map section.
  *
  * @return string []
  * @throws \Magento\Setup\Exception
  */
 public function getPaths()
 {
     // Locate composer.json for magento2-base module
     $filesPathList = [];
     $vendorDir = (require VENDOR_PATH);
     $basePackageComposerFilePath = $vendorDir . '/' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE;
     if (!$this->reader->isExist($basePackageComposerFilePath)) {
         throw new \Magento\Setup\Exception('Could not locate ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.');
     }
     if (!$this->reader->isReadable($basePackageComposerFilePath)) {
         throw new \Magento\Setup\Exception('Could not read ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.');
     }
     // Fill array with list of files and directories from extra/map section
     $composerJsonFileData = json_decode($this->reader->readFile($basePackageComposerFilePath), true);
     if (!isset($composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP])) {
         return $filesPathList;
     }
     $extraMappings = $composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP];
     foreach ($extraMappings as $map) {
         $filesPathList[] = $map[1];
     }
     return $filesPathList;
 }
Пример #9
0
 /**
  * Perform actual minification
  *
  * @return void
  */
 protected function minify()
 {
     $isExists = $this->staticViewDir->isExist($this->path);
     if (!$isExists) {
         $shouldMinify = true;
     } elseif ($this->strategy == self::FILE_EXISTS) {
         $shouldMinify = false;
     } else {
         $origlFile = $this->rootDir->getRelativePath($this->originalAsset->getSourceFile());
         $origMtime = $this->rootDir->stat($origlFile)['mtime'];
         $minMtime = $this->staticViewDir->stat($this->path)['mtime'];
         $shouldMinify = $origMtime != $minMtime;
     }
     if ($shouldMinify) {
         $content = $this->adapter->minify($this->originalAsset->getContent());
         $this->staticViewDir->writeFile($this->path, $content);
     }
 }
Пример #10
0
 /**
  * Check if Sample Data was deployed
  *
  * @return bool
  */
 public function isDeployed()
 {
     return $this->rootDir->isExist(self::PATH);
 }
Пример #11
0
 /**
  * Determines whether application is installed
  *
  * @return bool
  */
 private function isInstalled()
 {
     $this->init();
     return $this->configDir->isExist('local.xml');
 }