예제 #1
0
 /**
  * Get path to minified file
  *
  * @param string $originalFile
  * @return bool|string
  */
 public function getMinifiedFile($originalFile)
 {
     if ($this->_isFileMinified($originalFile)) {
         return $originalFile;
     }
     $originalFileRelative = $this->rootDirectory->getRelativePath($originalFile);
     $minifiedFile = $this->_findOriginalMinifiedFile($originalFileRelative);
     if (!$minifiedFile) {
         $minifiedFile = $this->directoryName . '/' . $this->_generateMinifiedFileName($originalFile);
         $this->_strategy->minifyFile($originalFileRelative, $minifiedFile);
     }
     $minifiedFile = $this->pubViewCacheDir->getRelativePath($minifiedFile);
     return $this->pubViewCacheDir->getAbsolutePath($minifiedFile);
 }
예제 #2
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \LogicException
  */
 public function launch()
 {
     if (!$this->_mediaDirectory) {
         $config = $this->_objectManager->create('Magento\\Core\\Model\\File\\Storage\\Config', ['cacheFile' => $this->_configCacheFile]);
         $config->save();
         $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory());
         $allowedResources = $config->getAllowedResources();
         $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo());
         $isAllowed = $this->_isAllowed;
         if (!$isAllowed($this->_relativeFileName, $allowedResources)) {
             throw new \LogicException('The specified path is not allowed.');
         }
     }
     if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) {
         throw new \LogicException('The specified path is not within media directory.');
     }
     $sync = $this->_objectManager->get('Magento\\Core\\Model\\File\\Storage\\Synchronization');
     $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath());
     if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) {
         $this->_response->setFilePath($this->_request->getFilePath());
     } else {
         $this->_response->setHttpResponseCode(404);
     }
     return $this->_response;
 }
예제 #3
0
 /**
  * Retrieve data from file
  *
  * @param string $file
  * @return array
  */
 protected function _getFileData($file)
 {
     $data = [];
     if ($this->directory->isExist($this->directory->getRelativePath($file))) {
         $this->_csvParser->setDelimiter(',');
         $data = $this->_csvParser->getDataPairs($file);
     }
     return $data;
 }
예제 #4
0
 /**
  * Go through all modules and find composer.json files of active modules
  *
  * @return FileIterator
  */
 public function getComposerJsonFiles()
 {
     $result = [];
     foreach ($this->modulesList->getNames() as $moduleName) {
         $file = $this->getModuleDir('', $moduleName) . '/composer.json';
         $path = $this->modulesDirectory->getRelativePath($file);
         if ($this->modulesDirectory->isExist($path)) {
             $result[] = $path;
         }
     }
     return $this->fileIteratorFactory->create($this->modulesDirectory, $result);
 }
예제 #5
0
 /**
  * Return default path related data
  *
  * @param string $configPath
  * @return array
  */
 protected function _preparePathData($configPath)
 {
     $themeDirectory = dirname($configPath);
     if ($this->_directory->isExist($themeDirectory)) {
         $fullPath = $this->_directory->getRelativePath($themeDirectory);
         $pathPieces = explode('/', $fullPath);
         $area = array_shift($pathPieces);
         return ['area' => $area, 'theme_path_pieces' => $pathPieces];
     } else {
         $fullPath = $this->rootDirectory->getRelativePath($themeDirectory);
         return $this->themeDirs->getAreaConfiguration($fullPath);
     }
 }
예제 #6
0
 /**
  * Open file and detect column names
  *
  * There must be column names in the first line
  *
  * @param string $file
  * @param \Magento\Framework\Filesystem\Directory\Read $directory
  * @param string $delimiter
  * @param string $enclosure
  * @throws \LogicException
  */
 public function __construct($file, \Magento\Framework\Filesystem\Directory\Read $directory, $delimiter = ',', $enclosure = '"')
 {
     register_shutdown_function([$this, 'destruct']);
     try {
         $this->_file = $directory->openFile($directory->getRelativePath($file), 'r');
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         throw new \LogicException("Unable to open file: '{$file}'");
     }
     if ($delimiter) {
         $this->_delimiter = $delimiter;
     }
     $this->_enclosure = $enclosure;
     parent::__construct($this->_getNextRow());
 }
예제 #7
0
 /**
  * Install application
  *
  * @param \Magento\Install\Model\Installer\Console $installer
  * @return void
  */
 protected function _handleInstall(\Magento\Install\Model\Installer\Console $installer)
 {
     if (isset($this->_arguments['config']) && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($this->_arguments['config']))) {
         $config = (array) (include $this->_arguments['config']);
         $this->_arguments = array_merge((array) $config, $this->_arguments);
     }
     $result = $installer->install($this->_arguments);
     if (!$installer->hasErrors()) {
         $msg = 'Installed successfully' . ($result ? ' (encryption key "' . $result . '")' : '');
         $this->_output->success($msg . PHP_EOL);
     } else {
         $this->_output->error(implode(PHP_EOL, $installer->getErrors()) . PHP_EOL);
     }
 }
예제 #8
0
 /**
  * Retrieve list of module action files
  *
  * @return array
  */
 public function getActionFiles()
 {
     $actions = array();
     foreach (array_keys($this->modulesList->getModules()) as $moduleName) {
         $actionDir = $this->getModuleDir('Controller', $moduleName);
         if (!file_exists($actionDir)) {
             continue;
         }
         $dirIterator = new \RecursiveDirectoryIterator($actionDir, \RecursiveDirectoryIterator::SKIP_DOTS);
         $recursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::LEAVES_ONLY);
         /** @var \SplFileInfo $actionFile */
         foreach ($recursiveIterator as $actionFile) {
             $actions[] = $this->modulesDirectory->getRelativePath($actionFile->getPathname());
         }
     }
     return $actions;
 }
예제 #9
0
파일: Carrier.php 프로젝트: aiesh/magento2
 /**
  * Get Country Params by Country Code
  *
  * @param string $countryCode
  * @return \Magento\Framework\Object
  *
  * @see $countryCode ISO 3166 Codes (Countries) A2
  */
 protected function getCountryParams($countryCode)
 {
     if (empty($this->_countryParams)) {
         $etcPath = $this->_configReader->getModuleDir('etc', 'Magento_Dhl');
         $countriesXmlPath = $this->modulesDirectory->getRelativePath($etcPath . '/countries.xml');
         $countriesXml = $this->modulesDirectory->readFile($countriesXmlPath);
         $this->_countryParams = $this->_xmlElFactory->create(array('data' => $countriesXml));
     }
     if (isset($this->_countryParams->{$countryCode})) {
         $countryParams = new \Magento\Framework\Object($this->_countryParams->{$countryCode}->asArray());
     }
     return isset($countryParams) ? $countryParams : new \Magento\Framework\Object();
 }
예제 #10
0
 /**
  * Return configuration model for themes
  *
  * @param string $configPath
  * @return \Magento\Framework\Config\Theme
  */
 protected function _getConfigModel($configPath)
 {
     $relativeConfigPath = $this->_directory->getRelativePath($configPath);
     $configContent = $this->_directory->isExist($relativeConfigPath) ? $this->_directory->readFile($relativeConfigPath) : null;
     return $this->themeConfigFactory->create(['configContent' => $configContent]);
 }
예제 #11
0
파일: Media.php 프로젝트: aiesh/magento2
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     try {
         if (!$this->_applicationState->isInstalled()) {
             $this->_response->setHttpResponseCode(404);
             return $this->_response;
         }
         if (!$this->_mediaDirectory) {
             $config = $this->_objectManager->create('Magento\\Core\\Model\\File\\Storage\\Config', array('cacheFile' => $this->_configCacheFile));
             $config->save();
             $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory());
             $allowedResources = $config->getAllowedResources();
             $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo());
             $isAllowed = $this->_isAllowed;
             if (!$isAllowed($this->_relativeFileName, $allowedResources)) {
                 $this->_response->setHttpResponseCode(404);
                 return $this->_response;
             }
         }
         if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) {
             $this->_response->setHttpResponseCode(404);
             return $this->_response;
         }
         $sync = $this->_objectManager->get('Magento\\Core\\Model\\File\\Storage\\Synchronization');
         $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath());
         if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) {
             $this->_response->setFilePath($this->_request->getFilePath());
         } else {
             $this->_response->setHttpResponseCode(404);
         }
         return $this->_response;
     } catch (\Exception $e) {
         $this->_response->setHttpResponseCode(404);
         return $this->_response;
     }
 }
예제 #12
0
 /**
  * Return configuration model for themes
  *
  * @param string $configPath
  * @return \Magento\Framework\Config\Theme
  */
 protected function _getConfigModel($configPath)
 {
     return new \Magento\Framework\Config\Theme($this->_directory->readFile($this->_directory->getRelativePath($configPath)));
 }