public function testCreateWithDriverCode()
 {
     $driverPool = $this->getMock('Magento\\Framework\\Filesystem\\DriverPool', ['getDriver']);
     $driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface');
     $driverMock->expects($this->any())->method('isExists')->willReturn(true);
     $driverPool->expects($this->once())->method('getDriver')->willReturn($driverMock);
     $factory = new ReadFactory($driverPool);
     $result = $factory->create('path', 'driverCode');
     $this->assertInstanceOf('Magento\\Framework\\Filesystem\\File\\Read', $result);
 }
示例#2
0
 /**
  * Retrieve Resource file handle (socket, file pointer etc)
  *
  * @return \Magento\Framework\Filesystem\File\ReadInterface
  * @throws CoreException|\Exception
  */
 protected function _getHandle()
 {
     if (!$this->_resourceFile) {
         throw new CoreException(__('Please set resource file and link type.'));
     }
     if (is_null($this->_handle)) {
         if ($this->_linkType == self::LINK_TYPE_URL) {
             $path = $this->_resourceFile;
             $protocol = strtolower(parse_url($path, PHP_URL_SCHEME));
             if ($protocol) {
                 // Strip down protocol from path
                 $path = preg_replace('#.+://#', '', $path);
             }
             $this->_handle = $this->fileReadFactory->create($path, $protocol);
         } elseif ($this->_linkType == self::LINK_TYPE_FILE) {
             $this->_workingDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
             $fileExists = $this->_downloadableFile->ensureFileInFilesystem($this->_resourceFile);
             if ($fileExists) {
                 $this->_handle = $this->_workingDirectory->openFile($this->_resourceFile);
             } else {
                 throw new CoreException(__('Invalid download link type.'));
             }
         } else {
             throw new CoreException(__('Invalid download link type.'));
         }
     }
     return $this->_handle;
 }
示例#3
0
文件: Read.php 项目: Mohitsahu123/mtf
 /**
  * Retrieve file contents from given path
  *
  * @param string $path
  * @param string|null $flag
  * @param resource|null $context
  * @param string|null $protocol
  * @return string
  * @throws FilesystemException
  */
 public function readFile($path, $flag = null, $context = null, $protocol = null)
 {
     $absolutePath = $this->driver->getAbsolutePath($this->path, $path, $protocol);
     /** @var \Magento\Framework\Filesystem\File\Read $fileReader */
     $fileReader = $this->fileFactory->create($absolutePath, $protocol, $this->driver);
     return $fileReader->readAll($flag, $context);
 }
示例#4
0
 /**
  * Get translation data
  *
  * @param string $themePath
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getData($themePath)
 {
     $areaCode = $this->appState->getAreaCode();
     $files = array_merge($this->filesUtility->getJsFiles('base', $themePath), $this->filesUtility->getJsFiles($areaCode, $themePath), $this->filesUtility->getStaticHtmlFiles('base', $themePath), $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath));
     $dictionary = [];
     foreach ($files as $filePath) {
         /** @var \Magento\Framework\Filesystem\File\Read $read */
         $read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE);
         $content = $read->readAll();
         foreach ($this->getPhrases($content) as $phrase) {
             $translatedPhrase = $this->translate->render([$phrase], []);
             if ($phrase != $translatedPhrase) {
                 $dictionary[$phrase] = $translatedPhrase;
             }
         }
     }
     return $dictionary;
 }
示例#5
0
 /**
  * Proceed moving a file from TMP to destination folder
  *
  * @param string $fileName
  * @return array
  */
 public function move($fileName)
 {
     if (preg_match('/\\bhttps?:\\/\\//i', $fileName, $matches)) {
         $url = str_replace($matches[0], '', $fileName);
         $read = $this->_readFactory->create($url, DriverPool::HTTP);
         $fileName = preg_replace('/[^a-z0-9\\._-]+/i', '', $fileName);
         $this->_directory->writeFile($this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName), $read->readAll());
     }
     $filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
     $this->_setUploadFile($filePath);
     $result = $this->save($this->getDestDir());
     $result['name'] = self::getCorrectFileName($result['name']);
     return $result;
 }
示例#6
0
 /**
  * Get aggregated distributed configuration
  *
  * @return string
  */
 public function getConfig()
 {
     $distributedConfig = '';
     $customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
     foreach ($customConfigFiles as $file) {
         /** @var $fileReader \Magento\Framework\Filesystem\File\Read */
         $fileReader = $this->readFactory->create($file->getFileName(), DriverPool::FILE);
         $config = $fileReader->readAll($file->getName());
         $distributedConfig .= str_replace(['%config%', '%context%'], [$config, $file->getModule()], self::PARTIAL_CONFIG_TEMPLATE);
     }
     $fullConfig = str_replace(['%function%', '%usages%'], [$distributedConfig], self::FULL_CONFIG_TEMPLATE);
     if ($this->minification->isEnabled('js')) {
         $fullConfig = $this->minifyAdapter->minify($fullConfig);
     }
     return $fullConfig;
 }
示例#7
0
 /**
  * @param string $path
  * @param string|null $protocol
  * @return ReadInterface
  */
 public function getRemoteResource($path, $protocol = null)
 {
     if (!$this->fileReadFactory) {
         // case when a temporary Filesystem object is used for loading primary configuration
         return null;
     }
     if (empty($protocol)) {
         $protocol = strtolower(parse_url($path, PHP_URL_SCHEME));
         if ($protocol) {
             // Strip down protocol from path
             $path = preg_replace('#.+://#', '', $path);
         }
     }
     if (!array_key_exists($protocol, $this->remoteResourceInstances)) {
         $this->remoteResourceInstances[$protocol] = $this->fileReadFactory->create($path, $protocol);
     }
     return $this->remoteResourceInstances[$protocol];
 }
示例#8
0
 /**
  * Open file in read mode
  *
  * @param string $path
  *
  * @return \Magento\Framework\Filesystem\File\ReadInterface
  */
 public function openFile($path)
 {
     return $this->fileFactory->create($this->driver->getAbsolutePath($this->path, $path), $this->driver);
 }
示例#9
0
 /**
  * Collect and merge layout updates from files
  *
  * @return \Magento\Framework\View\Layout\Element
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _loadFileLayoutUpdatesXml()
 {
     $layoutStr = '';
     $theme = $this->_getPhysicalTheme($this->theme);
     $updateFiles = $this->fileSource->getFiles($theme, '*.xml');
     $updateFiles = array_merge($updateFiles, $this->pageLayoutFileSource->getFiles($theme, '*.xml'));
     $useErrors = libxml_use_internal_errors(true);
     foreach ($updateFiles as $file) {
         /** @var $fileReader \Magento\Framework\Filesystem\File\Read   */
         $fileReader = $this->readFactory->create($file->getFilename(), DriverPool::FILE);
         $fileStr = $fileReader->readAll($file->getName());
         $fileStr = $this->_substitutePlaceholders($fileStr);
         /** @var $fileXml \Magento\Framework\View\Layout\Element */
         $fileXml = $this->_loadXmlString($fileStr);
         if (!$fileXml instanceof \Magento\Framework\View\Layout\Element) {
             $this->_logXmlErrors($file->getFilename(), libxml_get_errors());
             libxml_clear_errors();
             continue;
         }
         if (!$file->isBase() && $fileXml->xpath(self::XPATH_HANDLE_DECLARATION)) {
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Theme layout update file \'%1\' must not declare page types.', [$file->getFileName()]));
         }
         $handleName = basename($file->getFilename(), '.xml');
         $tagName = $fileXml->getName() === 'layout' ? 'layout' : 'handle';
         $handleAttributes = ' id="' . $handleName . '"' . $this->_renderXmlAttributes($fileXml);
         $handleStr = '<' . $tagName . $handleAttributes . '>' . $fileXml->innerXml() . '</' . $tagName . '>';
         $layoutStr .= $handleStr;
     }
     libxml_use_internal_errors($useErrors);
     $layoutStr = '<layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $layoutStr . '</layouts>';
     $layoutXml = $this->_loadXmlString($layoutStr);
     return $layoutXml;
 }
示例#10
0
 /**
  * Current
  *
  * @return string
  */
 public function current()
 {
     /** @var \Magento\Framework\Filesystem\File\Read $fileRead */
     $fileRead = $this->fileReadFactory->create($this->key(), DriverPool::FILE);
     return $fileRead->readAll();
 }