本文整理汇总了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();
}
示例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.'));
}
}
示例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();
}
示例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();
}
示例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;
}
示例6: testIsWritable
public function testIsWritable()
{
$this->driver->expects($this->once())->method('isWritable')->will($this->returnValue(true));
$this->assertTrue($this->write->isWritable('correct-path'));
}