當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Write::create方法代碼示例

本文整理匯總了PHP中Magento\Framework\Filesystem\Directory\Write::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Write::create方法的具體用法?PHP Write::create怎麽用?PHP Write::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Filesystem\Directory\Write的用法示例。


在下文中一共展示了Write::create方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUpBeforeClass

 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));
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:8,代碼來源:ConfigTest.php

示例2: __construct

 /**
  * Set base dir
  *
  * @param \Magento\Core\Model\EntityFactory $entityFactory
  * @param \Magento\Framework\App\Filesystem $filesystem
  */
 public function __construct(\Magento\Core\Model\EntityFactory $entityFactory, \Magento\Framework\App\Filesystem $filesystem)
 {
     parent::__construct($entityFactory);
     $this->filesystem = $filesystem;
     $this->connectDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->connectDirectory->create('connect');
     $this->addTargetDir($this->connectDirectory->getAbsolutePath('connect'));
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:14,代碼來源:Collection.php

示例3: __construct

 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Backend\Model\Session $session
  * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Backend\Model\Session $session, \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory)
 {
     parent::__construct($context);
     $this->filesystem = $filesystem;
     $this->_session = $session;
     $this->_themeFactory = $themeFactory;
     $this->mediaDirectoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->mediaDirectoryWrite->create($this->mediaDirectoryWrite->getRelativePath($this->getStorageRoot()));
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:15,代碼來源:Storage.php

示例4: _saveFatalErrorReport

 /**
  * Log information about fatal error.
  *
  * @param string $reportData
  * @return string
  */
 protected function _saveFatalErrorReport($reportData)
 {
     $this->directoryWrite->create('report/api');
     $reportId = abs(intval(microtime(true) * rand(100, 1000)));
     $this->directoryWrite->writeFile('report/api/' . $reportId, serialize($reportData));
     return $reportId;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:13,代碼來源:ErrorProcessor.php

示例5: check

 /**
  * 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;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:37,代碼來源:GenerationDirectoryAccess.php

示例6: resizeFile

 /**
  * Create thumbnail for image and save it to thumbnails directory
  *
  * @param string $source Image path to be resized
  * @param bool $keepRation Keep aspect ratio or not
  * @return bool|string Resized filepath or false if errors were occurred
  */
 public function resizeFile($source, $keepRation = true)
 {
     $realPath = $this->_directory->getRelativePath($source);
     if (!$this->_directory->isFile($realPath) || !$this->_directory->isExist($realPath)) {
         return false;
     }
     $targetDir = $this->getThumbsPath($source);
     $pathTargetDir = $this->_directory->getRelativePath($targetDir);
     if (!$this->_directory->isExist($pathTargetDir)) {
         $this->_directory->create($pathTargetDir);
     }
     if (!$this->_directory->isExist($pathTargetDir)) {
         return false;
     }
     $image = $this->_imageFactory->create();
     $image->open($source);
     $image->keepAspectRatio($keepRation);
     $image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']);
     $dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME);
     $image->save($dest);
     if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {
         return $dest;
     }
     return false;
 }
開發者ID:tingyeeh,項目名稱:magento2,代碼行數:32,代碼來源:Storage.php

示例7: createPackageV1x

 /**
  * 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;
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:20,代碼來源:Extension.php

示例8: createFolder

 /**
  * Create folder
  *
  * @param string $name
  * @param string $path
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function createFolder($name, $path)
 {
     if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Use only standard alphanumeric, dashes and underscores.'));
     }
     if (!$this->mediaWriteDirectory->isWritable($path)) {
         $path = $this->_helper->getStorageRoot();
     }
     $newPath = $path . '/' . $name;
     if ($this->mediaWriteDirectory->isExist($newPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found a directory with the same name.'));
     }
     $this->mediaWriteDirectory->create($newPath);
     $result = ['name' => $name, 'short_name' => $this->_helper->getShortFilename($name), 'path' => str_replace($this->_helper->getStorageRoot(), '', $newPath), 'id' => $this->_helper->convertPathToId($newPath)];
     return $result;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:24,代碼來源:Storage.php

示例9: getCurrentPath

 /**
  * 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;
 }
開發者ID:pavelnovitsky,項目名稱:magento2,代碼行數:31,代碼來源:Images.php

示例10: testCreate

 public function testCreate()
 {
     $this->driver->expects($this->once())->method('isDirectory')->will($this->returnValue(false));
     $this->driver->expects($this->once())->method('createDirectory')->will($this->returnValue(true));
     $this->assertTrue($this->write->create('correct-path'));
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:6,代碼來源:WriteTest.php


注:本文中的Magento\Framework\Filesystem\Directory\Write::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。