예제 #1
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Filesystem $filesystem
  * @param string $filename
  */
 public function __construct(\Magento\Framework\Filesystem $filesystem, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)
 {
     $this->filesystem = $filesystem;
     $this->filename = $filename;
     $this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
     $this->themeDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::THEMES);
 }
 /**
  * Check JSON file created by Setup cron command and Updater cron script
  *
  * @param string $type
  * @return array
  */
 private function checkJson($type)
 {
     $read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
     try {
         switch ($type) {
             case self::SETUP:
                 $key = ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED;
                 $jsonData = json_decode($read->readFile(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE), true);
                 break;
             case self::UPDATER:
                 $key = self::UPDATER_KEY_FILE_PERMISSIONS_VERIFIED;
                 $jsonData = json_decode($read->readFile(self::UPDATER_CRON_JOB_STATS_FILE), true);
                 break;
             default:
                 return ['success' => false, 'error' => 'Internal Error'];
         }
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         $error = 'Cron job has not been configured yet';
         if ($type == self::SETUP) {
             $error .= self::OTHER_CHECKS_WILL_FAIL_MSG;
         }
         return ['success' => false, 'error' => $error];
     }
     if (isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS]) && isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key])) {
         if ($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key]) {
             return $this->checkCronTime($jsonData);
         }
         return ['success' => false, 'error' => $jsonData[ReadinessCheck::KEY_READINESS_CHECKS]['error']];
     }
     $error = 'Cron job has not been configured yet';
     if ($type == self::SETUP) {
         $error .= self::OTHER_CHECKS_WILL_FAIL_MSG;
     }
     return ['success' => false, 'error' => $error];
 }
예제 #3
0
 /**
  * @param FileListFactory $fileListFactory
  * @param Filesystem $filesystem
  * @param Factory $fileFactory
  */
 public function __construct(FileListFactory $fileListFactory, Filesystem $filesystem, Factory $fileFactory)
 {
     $this->fileListFactory = $fileListFactory;
     $this->libraryDirectory = $filesystem->getDirectoryRead(DirectoryList::LIB_WEB);
     $this->themesDirectory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
     $this->fileFactory = $fileFactory;
 }
예제 #4
0
 public function testGetDirectoryRead()
 {
     /** @var \Magento\Framework\Filesystem\Directory\ReadInterface $dirReadMock */
     $dirReadMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->_dirReadFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirReadMock));
     $this->assertEquals($dirReadMock, $this->_filesystem->getDirectoryRead(DirectoryList::ROOT));
 }
예제 #5
0
 /**
  * Save uploaded file and set its name to category
  *
  * @param \Magento\Framework\DataObject $object
  * @return \Magento\Catalog\Model\Category\Attribute\Backend\Image
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName() . '_additional_data');
     // if no image was set - nothing to do
     if (empty($value) && empty($_FILES)) {
         return $this;
     }
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return $this;
     }
     $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/category/');
     try {
         /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
         $uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
         $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (\Exception $e) {
         if ($e->getCode() != \Magento\MediaStorage\Model\File\Uploader::TMP_NAME_EMPTY) {
             $this->_logger->critical($e);
         }
     }
     return $this;
 }
예제 #6
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Filesystem $filesystem
  * @param ComponentRegistrarInterface $componentRegistrar
  * @param string $filename
  */
 public function __construct(\Magento\Framework\Filesystem $filesystem, ComponentRegistrarInterface $componentRegistrar, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)
 {
     $this->filesystem = $filesystem;
     $this->filename = $filename;
     $this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
     $this->componentRegistrar = $componentRegistrar;
 }
예제 #7
0
 /**
  * Image upload action in iframe
  *
  * @return string
  */
 public function execute()
 {
     try {
         $uploader = $this->uploaderFactory->create(['fileId' => 'datafile']);
         $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
         /** @var \Magento\Framework\Image\Adapter\AdapterInterface $imageAdapter */
         $imageAdapter = $this->adapterFactory->create();
         $uploader->addValidateCallback('catalog_product_image', $imageAdapter, 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         /** @var \Magento\Framework\Filesystem\Directory\Read $mediaDirectory */
         $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
         $config = $this->config;
         $result = $uploader->save($mediaDirectory->getAbsolutePath($config->getBaseTmpMediaPath()));
         $this->_eventManager->dispatch('swatch_gallery_upload_image_after', ['result' => $result, 'action' => $this]);
         unset($result['tmp_name']);
         unset($result['path']);
         $result['url'] = $this->config->getTmpMediaUrl($result['file']);
         $result['file'] = $result['file'] . '.tmp';
         $newFile = $this->swatchHelper->moveImageFromTmp($result['file']);
         $this->swatchHelper->generateSwatchVariations($newFile);
         $fileData = ['swatch_path' => $this->swatchHelper->getSwatchMediaUrl(), 'file_path' => $newFile];
         $this->getResponse()->setBody(json_encode($fileData));
     } catch (\Exception $e) {
         $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
         $this->getResponse()->setBody(json_encode($result));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->updateMemoryLimit();
     $sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
     if (!empty($sampleDataPackages)) {
         $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
         $commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1];
         $packages = [];
         foreach ($sampleDataPackages as $name => $version) {
             $packages[] = "{$name}:{$version}";
         }
         $commonArgs = array_merge(['packages' => $packages], $commonArgs);
         $arguments = array_merge(['command' => 'require'], $commonArgs);
         /** @var ArrayInput $commandInput */
         $commandInput = $this->arrayInputFactory->create(['parameters' => $arguments]);
         /** @var Application $application */
         $application = $this->applicationFactory->create();
         $application->setAutoExit(false);
         $result = $application->run($commandInput, $output);
         if ($result !== 0) {
             $output->writeln('<info>' . 'There is an error during sample data deployment.' . '</info>');
         }
     } else {
         $output->writeln('<info>' . 'There is no sample data for current set of modules.' . '</info>');
     }
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
 {
     $dir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
     if (!$dir->isExist($resultAsset->getPath())) {
         $this->strategy->merge($assetsToMerge, $resultAsset);
     }
 }
예제 #10
0
파일: Upload.php 프로젝트: swnsma/practice
 /**
  * Validate image size.
  *
  * @param $filePath
  *
  * @throws LocalizedException
  */
 public function sizeValidate($filePath)
 {
     $directory = $this->_filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
     if ($this->_maxSize > 0 && $directory->stat($directory->getRelativePath($filePath))['size'] > $this->_maxSize * 1024) {
         throw new LocalizedException(__('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxSize));
     }
 }
예제 #11
0
 /**
  * After save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this|void
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     try {
         /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
         $uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
         $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
     } catch (\Exception $e) {
         return $this;
     }
     $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/product/');
     $uploader->save($path);
     $fileName = $uploader->getUploadedFileName();
     if ($fileName) {
         $object->setData($this->getAttribute()->getName(), $fileName);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     return $this;
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function read($sessionId)
 {
     try {
         return parent::read($sessionId);
     } catch (ConcurrentConnectionsExceededException $e) {
         require $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/503.php');
     }
 }
예제 #13
0
 /**
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 public function publish(Asset\LocalInterface $asset)
 {
     $dir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
     if ($dir->isExist($asset->getPath())) {
         return true;
     }
     return $this->publishAsset($asset);
 }
예제 #14
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\Config\ThemeFactory $themeConfigFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Config\ThemeFactory $themeConfigFactory, \Magento\Framework\Module\ThemeDir $themeDirs)
 {
     parent::__construct($entityFactory);
     $this->_directory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
     $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
     $this->themeConfigFactory = $themeConfigFactory;
     $this->themeDirs = $themeDirs;
 }
예제 #15
0
 /**
  * Constructor
  *
  * @param Filesystem $filesystem
  * @param Factory $fileFactory
  * @param string $subDir
  */
 public function __construct(Filesystem $filesystem, Factory $fileFactory, \Magento\Framework\Module\ThemeDir $themeDirs, $subDir = '')
 {
     $this->themesDirectory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
     $this->themeDirs = $themeDirs;
     $this->fileFactory = $fileFactory;
     $this->subDir = $subDir ? $subDir . '/' : '';
     $this->modulesDir = $filesystem->getDirectoryRead(DirectoryList::MODULES);
 }
예제 #16
0
 /**
  * Clean files in database on cleaning merged assets
  *
  * @param \Magento\Framework\View\Asset\MergeService $subject
  * @param callable $proceed
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundCleanMergedJsCss(\Magento\Framework\View\Asset\MergeService $subject, \Closure $proceed)
 {
     $proceed();
     /** @var \Magento\Framework\Filesystem\Directory\ReadInterface $pubStaticDirectory */
     $pubStaticDirectory = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
     $mergedDir = $pubStaticDirectory->getAbsolutePath() . '/' . \Magento\Framework\View\Asset\Merged::getRelativeDir();
     $this->database->deleteFolder($mergedDir);
 }
예제 #17
0
 /**
  * @param ImageContentInterface $imageContent
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function processFileContent(ImageContentInterface $imageContent)
 {
     $filePath = $this->saveFile($imageContent);
     $fileAbsolutePath = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath($filePath);
     $fileHash = md5($this->filesystem->getDirectoryRead(DirectoryList::ROOT)->readFile($filePath));
     $imageSize = getimagesize($fileAbsolutePath);
     $result = ['type' => $imageContent->getType(), 'title' => $imageContent->getName(), 'fullpath' => $fileAbsolutePath, 'quote_path' => $filePath, 'order_path' => $filePath, 'size' => filesize($fileAbsolutePath), 'width' => $imageSize ? $imageSize[0] : 0, 'height' => $imageSize ? $imageSize[1] : 0, 'secret_key' => substr($fileHash, 0, 20)];
     return $result;
 }
예제 #18
0
 /**
  * @return string
  */
 protected function getLockFile()
 {
     $lockFileDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath();
     $lockFile = $lockFileDir . DIRECTORY_SEPARATOR . $this->lockFileName;
     if (!$this->filesystemDriver->isExists($lockFile)) {
         $this->filesystemDriver->filePutContents($lockFile, 0);
     }
     return $lockFile;
 }
예제 #19
0
 /**
  * Constructor
  *
  * @param Filesystem $filesystem
  */
 public function __construct(Filesystem $filesystem)
 {
     $vendor = $filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath('vendor_path.php');
     $vendorPath = $filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() . (include $vendor);
     // Create Composer
     $io = new \Composer\IO\BufferIO();
     $this->composer = ComposerFactory::create($io, $vendorPath . '/../composer.json');
     $this->locker = $this->composer->getLocker();
 }
예제 #20
0
 /**
  * @param FileListFactory $fileListFactory
  * @param Filesystem $filesystem
  * @param Factory $fileFactory
  */
 public function __construct(FileListFactory $fileListFactory, Filesystem $filesystem, Factory $fileFactory, \Magento\Framework\Module\ThemeDir $themeDir)
 {
     $this->fileListFactory = $fileListFactory;
     $this->libraryDirectory = $filesystem->getDirectoryRead(DirectoryList::LIB_WEB);
     $this->themesDirectory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
     $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
     $this->fileFactory = $fileFactory;
     $this->themeDir = $themeDir;
 }
예제 #21
0
 /**
  * Init
  *
  * @param \Magento\Framework\Module\Setup\Context $context
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Module\Setup\Context $context, $connectionName = ModuleDataSetupInterface::DEFAULT_SETUP_CONNECTION)
 {
     parent::__construct($context->getResourceModel(), $connectionName);
     $this->_eventManager = $context->getEventManager();
     $this->_logger = $context->getLogger();
     $this->_modulesReader = $context->getModulesReader();
     $this->_migrationFactory = $context->getMigrationFactory();
     $this->filesystem = $context->getFilesystem();
     $this->modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
     $this->setupCache = new SetupCache();
 }
예제 #22
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     $directoryRead = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
     if (!$directoryRead->isDirectory('report')) {
         $count = 0;
         // currently we have no error report
     } else {
         $count = $this->getFileCount($directoryRead->getAbsolutePath('report'));
     }
     $output->writeln($count);
 }
예제 #23
0
 /**
  * Prepare link to display in grid
  *
  * @param \Magento\Framework\DataObject $row
  * @return string
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     /** @var $sitemap \Magento\Sitemap\Model\Sitemap */
     $sitemap = $this->_sitemapFactory->create();
     $url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));
     $fileName = preg_replace('/^\\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
     $directory = $this->_filesystem->getDirectoryRead(DirectoryList::ROOT);
     if ($directory->isFile($fileName)) {
         return sprintf('<a href="%1$s">%1$s</a>', $url);
     }
     return $url;
 }
예제 #24
0
 public function toArray()
 {
     $themes = $this->_collectionThemeFactory->create();
     $file = $this->_filesystem->getDirectoryRead(DirectoryList::APP)->getAbsolutePath('design/frontend/');
     $vesPackagePaths = glob($file . '*/*/config.xml');
     $output = [];
     foreach ($vesPackagePaths as $k => $v) {
         $v = str_replace("/config.xml", "", $v);
         $output[str_replace($file, "", $v)] = ucfirst(str_replace($file, "", $v));
     }
     return $output;
 }
예제 #25
0
 /**
  * @param \Magento\Framework\Module\Setup\Context $context
  * @param string $resourceName
  * @param string $moduleName
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Module\Setup\Context $context, $resourceName, $moduleName, $connectionName = \Magento\Framework\Module\Updater\SetupInterface::DEFAULT_SETUP_CONNECTION)
 {
     parent::__construct($context->getResourceModel(), $connectionName);
     $this->_eventManager = $context->getEventManager();
     $this->_logger = $context->getLogger();
     $this->_modulesReader = $context->getModulesReader();
     $this->_resourceName = $resourceName;
     $this->_resource = $context->getResource();
     $this->_migrationFactory = $context->getMigrationFactory();
     $this->_moduleConfig = $context->getModuleList()->getOne($moduleName);
     $this->filesystem = $context->getFilesystem();
     $this->modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
 }
예제 #26
0
 /**
  * Constructor
  *
  * @param Filesystem $filesystem
  * @param BufferIoFactory $bufferIoFactory
  * @throws \Exception
  */
 public function __construct(Filesystem $filesystem, BufferIoFactory $bufferIoFactory)
 {
     // composer.json is in same directory as vendor
     $vendorPath = $filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath('vendor_path.php');
     $vendorDir = (require "{$vendorPath}");
     $composerJson = $filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() . "/{$vendorDir}/../composer.json";
     $composerJsonRealPath = realpath($composerJson);
     if ($composerJsonRealPath === false) {
         throw new \Exception('Composer file not found: ' . $composerJson);
     }
     putenv('COMPOSER_HOME=' . $filesystem->getDirectoryRead(DirectoryList::COMPOSER_HOME)->getAbsolutePath());
     // Create Composer
     $this->composer = ComposerFactory::create($bufferIoFactory->create(), $composerJson);
     $this->locker = $this->composer->getLocker();
 }
예제 #27
0
 /**
  * Create Backup
  *
  * @return $this
  */
 public function execute()
 {
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(true);
     }
     $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
     $this->_errors = [];
     try {
         $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir());
         $this->_coreRegistry->register('backup_manager', $backupManager);
         if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
             $backupManager->setRootDir($this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($this->_backupData->getBackupIgnorePaths());
         }
         $backupManager->create();
         $message = $this->_backupData->getCreateSuccessMessageByType($type);
         $this->_logger->info($message);
     } catch (\Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         $this->_logger->info($e->getMessage());
         $this->_logger->critical($e);
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(false);
     }
     return $this;
 }
예제 #28
0
 /**
  * @param \Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource
  * @param \Magento\Framework\View\DesignInterface $design
  * @param \Magento\Framework\Filesystem $appFilesystem
  * @param \Magento\Framework\View\Asset\Repository $assetRepo
  */
 public function __construct(\Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Filesystem $appFilesystem, \Magento\Framework\View\Asset\Repository $assetRepo)
 {
     $this->fileSource = $fileSource;
     $this->design = $design;
     $this->baseDir = $appFilesystem->getDirectoryRead(DirectoryList::ROOT);
     $this->staticContext = $assetRepo->getStaticViewFileContext();
 }
예제 #29
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;
 }
예제 #30
0
 /**
  * Return newly created cache frontend instance
  *
  * @param array $options
  * @return \Magento\Framework\Cache\FrontendInterface
  */
 public function create(array $options)
 {
     $options = $this->_getExpandedOptions($options);
     foreach (['backend_options', 'slow_backend_options'] as $section) {
         if (!empty($options[$section]['cache_dir'])) {
             $directory = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
             $directory->create($options[$section]['cache_dir']);
             $options[$section]['cache_dir'] = $directory->getAbsolutePath($options[$section]['cache_dir']);
         }
     }
     $idPrefix = isset($options['id_prefix']) ? $options['id_prefix'] : '';
     if (!$idPrefix && isset($options['prefix'])) {
         $idPrefix = $options['prefix'];
     }
     if (empty($idPrefix)) {
         $configDirPath = $this->_filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath();
         $idPrefix = substr(md5($configDirPath), 0, 3) . '_';
     }
     $options['frontend_options']['cache_id_prefix'] = $idPrefix;
     $backend = $this->_getBackendOptions($options);
     $frontend = $this->_getFrontendOptions($options);
     // Start profiling
     $profilerTags = ['group' => 'cache', 'operation' => 'cache:create', 'frontend_type' => $frontend['type'], 'backend_type' => $backend['type']];
     \Magento\Framework\Profiler::start('cache_frontend_create', $profilerTags);
     /** @var $result \Magento\Framework\Cache\Frontend\Adapter\Zend */
     $result = $this->_objectManager->create('Magento\\Framework\\Cache\\Frontend\\Adapter\\Zend', ['frontend' => \Zend_Cache::factory($frontend['type'], $backend['type'], $frontend, $backend['options'], true, true, true)]);
     $result = $this->_applyDecorators($result);
     // stop profiling
     \Magento\Framework\Profiler::stop('cache_frontend_create');
     return $result;
 }