コード例 #1
0
ファイル: ConfigTest.php プロジェクト: aiesh/magento2
 public static function setUpBeforeClass()
 {
     /** @var \Magento\Framework\App\Filesystem $filesystem */
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Filesystem');
     self::$_varDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     self::$_tmpDir = self::$_varDirectory->getAbsolutePath('ConfigTest');
     self::$_varDirectory->create(self::$_varDirectory->getRelativePath(self::$_tmpDir));
 }
コード例 #2
0
 protected function setUp()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->varDirectory = $objectManager->get('Magento\\Framework\\Filesystem')->getDirectoryWrite(DirectoryList::VAR_DIR);
     $generationDirectory = $this->varDirectory->getAbsolutePath('generation');
     $this->_ioObject = new \Magento\Framework\Code\Generator\Io(new \Magento\Framework\Filesystem\Driver\File(), $generationDirectory);
     $this->_generator = $objectManager->create('Magento\\Framework\\Code\\Generator', ['ioObject' => $this->_ioObject, 'generatedEntities' => [DIGenerator\Factory::ENTITY_TYPE => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Factory', DIGenerator\Proxy::ENTITY_TYPE => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Proxy', InterceptionGenerator\Interceptor::ENTITY_TYPE => '\\Magento\\Framework\\Interception\\Code\\Generator\\Interceptor']]);
     $this->_generator->setObjectManager($objectManager);
 }
コード例 #3
0
ファイル: GeneratorTest.php プロジェクト: aiesh/magento2
 protected function setUp()
 {
     $this->_includePath = get_include_path();
     $this->varDirectory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Filesystem')->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     $generationDirectory = $this->varDirectory->getAbsolutePath('generation');
     (new \Magento\Framework\Autoload\IncludePath())->addIncludePath($generationDirectory);
     $this->_ioObject = new \Magento\Framework\Code\Generator\Io(new \Magento\Framework\Filesystem\Driver\File(), new \Magento\Framework\Autoload\IncludePath(), $generationDirectory);
     $this->_generator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Code\\Generator', array('ioObject' => $this->_ioObject, 'generatedEntities' => array(DIGenerator\Factory::ENTITY_TYPE => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Factory', DIGenerator\Proxy::ENTITY_TYPE => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Proxy', InterceptionGenerator\Interceptor::ENTITY_TYPE => '\\Magento\\Framework\\Interception\\Code\\Generator\\Interceptor')));
 }
コード例 #4
0
 /**
  * @covers \Magento\Theme\Model\Wysiwyg\Storage::_createThumbnail
  */
 public function testCreateThumbnail()
 {
     $image = 'some_image.jpg';
     $imagePath = realpath(__DIR__) . "/_files/theme/image/{$image}";
     $tmpImagePath = $this->_copyFileToTmpCustomizationPath($imagePath);
     $relativePath = $this->directoryTmp->getRelativePath($tmpImagePath);
     $method = $this->_getMethod('_createThumbnail');
     $result = $method->invokeArgs($this->_storageModel, array($relativePath));
     $expectedResult = $this->directoryTmp->getRelativePath($this->_helperStorage->getThumbnailDirectory($tmpImagePath) . '/' . $image);
     $this->assertEquals($expectedResult, $result);
     $this->assertFileExists($this->directoryTmp->getAbsolutePath($result));
 }
コード例 #5
0
ファイル: Storage.php プロジェクト: tingyeeh/magento2
 /**
  * Thumbnail URL getter
  *
  * @param  string $filePath original file path
  * @param  bool $checkFile OPTIONAL is it necessary to check file availability
  * @return string|false
  */
 public function getThumbnailUrl($filePath, $checkFile = false)
 {
     $mediaRootDir = $this->_cmsWysiwygImages->getStorageRoot();
     if (strpos($filePath, $mediaRootDir) === 0) {
         $thumbSuffix = self::THUMBS_DIRECTORY_NAME . substr($filePath, strlen($mediaRootDir));
         if (!$checkFile || $this->_directory->isExist($this->_directory->getRelativePath($mediaRootDir . '/' . $thumbSuffix))) {
             $thumbSuffix = substr($mediaRootDir, strlen($this->_directory->getAbsolutePath())) . '/' . $thumbSuffix;
             $randomIndex = '?rand=' . time();
             return str_replace('\\', '/', $this->_cmsWysiwygImages->getBaseUrl() . $thumbSuffix) . $randomIndex;
         }
     }
     return false;
 }
コード例 #6
0
ファイル: Collection.php プロジェクト: Atlis/docker-magento2
 /**
  * Get all folders as options array
  *
  * @return array
  */
 public function collectFolders()
 {
     $collectFiles = $this->_collectFiles;
     $collectDirs = $this->_collectDirs;
     $this->setCollectFiles(false)->setCollectDirs(true);
     $this->_collectRecursive($this->connectDirectory->getAbsolutePath('connect'));
     $result = array('/' => '/');
     foreach ($this->_collectedDirs as $dir) {
         $dir = substr($this->connectDirectory->getRelativePath($dir), strlen('connect/')) . '/';
         $result[$dir] = $dir;
     }
     $this->setCollectFiles($collectFiles)->setCollectDirs($collectDirs);
     return $result;
 }
コード例 #7
0
ファイル: Extension.php プロジェクト: Atlis/docker-magento2
 /**
  * Create package file compatible with previous version of Magento Connect Manager
  *
  * @return boolean
  */
 public function createPackageV1x()
 {
     try {
         $this->writeDirectory->create('pear/');
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION);
         $this->logger->log($e->getMessage());
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     $this->getPackage()->saveV1x($this->writeDirectory->getAbsolutePath('pear/'));
     return true;
 }
コード例 #8
0
ファイル: File.php プロジェクト: aiesh/magento2
 /**
  * Export attribute value to entity model
  *
  * @param array|string $value
  * @return $this
  */
 public function compactValue($value)
 {
     if ($this->getIsAjaxRequest()) {
         return $this;
     }
     $attribute = $this->getAttribute();
     $original = $this->getEntity()->getData($attribute->getAttributeCode());
     $toDelete = false;
     if ($original) {
         if (!$attribute->getIsRequired() && !empty($value['delete'])) {
             $toDelete = true;
         }
         if (!empty($value['tmp_name'])) {
             $toDelete = true;
         }
     }
     $destinationFolder = $attribute->getEntity()->getEntityTypeCode();
     // unlink entity file
     if ($toDelete) {
         $this->getEntity()->setData($attribute->getAttributeCode(), '');
         $file = $destinationFolder . $original;
         if ($this->_directory->isExist($file)) {
             $this->_directory->delete($file);
         }
     }
     if (!empty($value['tmp_name'])) {
         try {
             $uploader = new \Magento\Framework\File\Uploader($value);
             $uploader->setFilesDispersion(true);
             $uploader->setFilenamesCaseSensitivity(false);
             $uploader->setAllowRenameFiles(true);
             $uploader->save($this->_directory->getAbsolutePath($destinationFolder), $value['name']);
             $fileName = $uploader->getUploadedFileName();
             $this->getEntity()->setData($attribute->getAttributeCode(), $fileName);
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     return $this;
 }
コード例 #9
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;
 }
コード例 #10
0
ファイル: Images.php プロジェクト: pavelnovitsky/magento2
 /**
  * Return path of the current selected directory or root directory for startup
  * Try to create target directory if it doesn't exist
  *
  * @return string
  * @throws \Magento\Framework\Model\Exception
  */
 public function getCurrentPath()
 {
     if (!$this->_currentPath) {
         $currentPath = $this->_directory->getAbsolutePath() . \Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY;
         $path = $this->_getRequest()->getParam($this->getTreeNodeName());
         if ($path) {
             $path = $this->convertIdToPath($path);
             if ($this->_directory->isDirectory($this->_directory->getRelativePath($path))) {
                 $currentPath = $path;
             }
         }
         try {
             $currentDir = $this->_directory->getRelativePath($currentPath);
             if (!$this->_directory->isExist($currentDir)) {
                 $this->_directory->create($currentDir);
             }
         } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
             $message = __('The directory %1 is not writable by server.', $currentPath);
             throw new \Magento\Framework\Model\Exception($message);
         }
         $this->_currentPath = $currentPath;
     }
     return $this->_currentPath;
 }
コード例 #11
0
ファイル: Sitemap.php プロジェクト: aiesh/magento2
 /**
  * Get base dir
  *
  * @return string
  */
 protected function _getBaseDir()
 {
     return $this->_directory->getAbsolutePath();
 }