当前位置: 首页>>代码示例>>PHP>>正文


PHP Write::isWritable方法代码示例

本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP Write::isWritable方法的具体用法?PHP Write::isWritable怎么用?PHP Write::isWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Filesystem\Directory\Write的用法示例。


在下文中一共展示了Write::isWritable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeSave

 /**
  * Check sitemap file location and permissions
  *
  * @return \Magento\Framework\Model\AbstractModel
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function beforeSave()
 {
     $path = $this->getSitemapPath();
     /**
      * Check path is allow
      */
     if ($path && preg_match('#\\.\\.[\\\\/]#', $path)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please define a correct path.'));
     }
     /**
      * Check exists and writable path
      */
     if (!$this->_directory->isExist($path)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please create the specified folder "%1" before saving the sitemap.', $this->_escaper->escapeHtml($this->getSitemapPath())));
     }
     if (!$this->_directory->isWritable($path)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please make sure that "%1" is writable by the web-server.', $this->getSitemapPath()));
     }
     /**
      * Check allow filename
      */
     if (!preg_match('#^[a-zA-Z0-9_\\.]+$#', $this->getSitemapFilename())) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please use only letters (a-z or A-Z), numbers (0-9) or underscores (_) in the filename. No spaces or other characters are allowed.'));
     }
     if (!preg_match('#\\.xml$#', $this->getSitemapFilename())) {
         $this->setSitemapFilename($this->getSitemapFilename() . '.xml');
     }
     $this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', $this->_getBaseDir()), '', $path), '/') . '/');
     return parent::beforeSave();
 }
开发者ID:nja78,项目名称:magento2,代码行数:36,代码来源:Sitemap.php

示例2: createDirectory

 /**
  * Create new directory in storage
  *
  * @param string $name New directory name
  * @param string $path Parent directory path
  * @return array New directory info
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function createDirectory($name, $path)
 {
     if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please rename the folder using only letters, numbers, underscores and dashes.'));
     }
     $relativePath = $this->_directory->getRelativePath($path);
     if (!$this->_directory->isDirectory($relativePath) || !$this->_directory->isWritable($relativePath)) {
         $path = $this->_cmsWysiwygImages->getStorageRoot();
     }
     $newPath = $path . '/' . $name;
     $relativeNewPath = $this->_directory->getRelativePath($newPath);
     if ($this->_directory->isDirectory($relativeNewPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found a directory with the same name. Please try another folder name.'));
     }
     $this->_directory->create($relativeNewPath);
     try {
         if ($this->_coreFileStorageDb->checkDbUsage()) {
             $relativePath = $this->_coreFileStorageDb->getMediaRelativePath($newPath);
             $this->_directoryDatabaseFactory->create()->createRecursive($relativePath);
         }
         $result = ['name' => $name, 'short_name' => $this->_cmsWysiwygImages->getShortFilename($name), 'path' => $newPath, 'id' => $this->_cmsWysiwygImages->convertPathToId($newPath)];
         return $result;
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a new directory.'));
     }
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:34,代码来源:Storage.php

示例3: __construct

 /**
  * Constructor
  *
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param string|null $destination
  * @throws \Magento\Framework\Model\Exception
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, $destination = null)
 {
     $this->_directoryHandle = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
     if (!$destination) {
         $destination = uniqid('importexport_');
         $this->_directoryHandle->touch($destination);
     }
     if (!is_string($destination)) {
         throw new \Magento\Framework\Model\Exception(__('Destination file path must be a string'));
     }
     if (!$this->_directoryHandle->isWritable()) {
         throw new \Magento\Framework\Model\Exception(__('Destination directory is not writable'));
     }
     if ($this->_directoryHandle->isFile($destination) && !$this->_directoryHandle->isWritable($destination)) {
         throw new \Magento\Framework\Model\Exception(__('Destination file is not writable'));
     }
     $this->_destination = $destination;
     $this->_init();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:26,代码来源:AbstractAdapter.php

示例4: __construct

 /**
  * Constructor
  *
  * @param Filesystem $filesystem
  * @param string|null $destination
  * @param string $destinationDirectoryCode
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function __construct(\Magento\Framework\Filesystem $filesystem, $destination = null, $destinationDirectoryCode = DirectoryList::SYS_TMP)
 {
     $this->_directoryHandle = $filesystem->getDirectoryWrite($destinationDirectoryCode);
     if (!$destination) {
         $destination = uniqid('importexport_');
         $this->_directoryHandle->touch($destination);
     }
     if (!is_string($destination)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The destination file path must be a string.'));
     }
     if (!$this->_directoryHandle->isWritable()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The destination directory is not writable.'));
     }
     if ($this->_directoryHandle->isFile($destination) && !$this->_directoryHandle->isWritable($destination)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Destination file is not writable'));
     }
     $this->_destination = $destination;
     $this->_init();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:27,代码来源:AbstractAdapter.php

示例5: 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

示例6: testIsWritable

 public function testIsWritable()
 {
     $this->driver->expects($this->once())->method('isWritable')->will($this->returnValue(true));
     $this->assertTrue($this->write->isWritable('correct-path'));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:5,代码来源:WriteTest.php


注:本文中的Magento\Framework\Filesystem\Directory\Write::isWritable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。