コード例 #1
0
 /**
  * Check var/generation read and write access
  *
  * @return bool
  */
 public function check()
 {
     $initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
     $filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
     $directoryList = new DirectoryList(BP, $filesystemDirPaths);
     $generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
     $driverPool = new DriverPool();
     $fileWriteFactory = new WriteFactory($driverPool);
     /** @var \Magento\Framework\Filesystem\DriverInterface $driver */
     $driver = $driverPool->getDriver(DriverPool::FILE);
     $directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
     if ($directoryWrite->isExist()) {
         if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
             try {
                 $probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
                 $fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
                 $driver->deleteFile($probeFilePath);
             } catch (\Exception $e) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         try {
             $directoryWrite->create();
         } catch (\Exception $e) {
             return false;
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Load composer packages available for update from cache
  *
  * @return bool|string
  */
 private function loadPackagesForUpdateFromCache()
 {
     if ($this->directory->isExist($this->pathToCacheFile) && $this->directory->isReadable($this->pathToCacheFile)) {
         try {
             $data = $this->directory->readFile($this->pathToCacheFile);
             return json_decode($data, true);
         } catch (\Magento\Framework\Exception\FileSystemException $e) {
         }
     }
     return false;
 }
コード例 #3
0
 /**
  * Create thumbnail for image and save it to thumbnails directory
  *
  * @param string $source
  * @return bool|string Resized filepath or false if errors were occurred
  */
 public function _createThumbnail($source)
 {
     if (self::TYPE_IMAGE != $this->_helper->getStorageType() || !$this->mediaWriteDirectory->isFile($source) || !$this->mediaWriteDirectory->isReadable($source)) {
         return false;
     }
     $thumbnailDir = $this->_helper->getThumbnailDirectory($source);
     $thumbnailPath = $thumbnailDir . '/' . pathinfo($source, PATHINFO_BASENAME);
     try {
         $this->mediaWriteDirectory->isExist($thumbnailDir);
         $image = $this->_imageFactory->create();
         $image->open($this->mediaWriteDirectory->getAbsolutePath($source));
         $image->keepAspectRatio(true);
         $image->resize(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT);
         $image->save($this->mediaWriteDirectory->getAbsolutePath($thumbnailPath));
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         return false;
     }
     if ($this->mediaWriteDirectory->isFile($thumbnailPath)) {
         return $thumbnailPath;
     }
     return false;
 }