本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write::isDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Write::isDirectory方法的具体用法?PHP Write::isDirectory怎么用?PHP Write::isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\Write
的用法示例。
在下文中一共展示了Write::isDirectory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
/**
* Clear temporary directories
*
* @param \Magento\Install\Controller\Index\Index $subject
* @param \Magento\Framework\App\RequestInterface $request
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(\Magento\Install\Controller\Index\Index $subject, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->appState->isInstalled()) {
foreach ($this->varDirectory->read() as $dir) {
if ($this->varDirectory->isDirectory($dir)) {
try {
$this->varDirectory->delete($dir);
} catch (FilesystemException $exception) {
$this->logger->log($exception->getMessage());
}
}
}
}
}
示例2: 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;
}
示例3: 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.'));
}
}
示例4: _copyFilesRecursively
/**
* Copies all files in a directory recursively
*
* @param string $baseDir
* @param string $sourceDir
* @param string $targetDir
* @return void
*/
protected function _copyFilesRecursively($baseDir, $sourceDir, $targetDir)
{
foreach ($this->_directory->read($sourceDir) as $path) {
if ($this->_directory->isDirectory($path)) {
$this->_copyFilesRecursively($baseDir, $path, $targetDir);
} else {
$filePath = substr($path, strlen($baseDir) + 1);
$this->_directory->copyFile($path, $targetDir . '/' . $filePath);
}
}
}
示例5: getDirsCollection
/**
* Get directory collection
*
* @param string $currentPath
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getDirsCollection($currentPath)
{
if (!$this->mediaWriteDirectory->isExist($currentPath)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot find a directory with this name.'));
}
$paths = $this->mediaWriteDirectory->search('.*', $currentPath);
$directories = [];
foreach ($paths as $path) {
if ($this->mediaWriteDirectory->isDirectory($path)) {
$directories[] = $path;
}
}
return $directories;
}
示例6: getCurrentPath
/**
* Get current path
*
* @return string
*/
public function getCurrentPath()
{
if (!$this->_currentPath) {
$currentPath = $this->getStorageRoot();
$path = $this->_getRequest()->getParam(self::PARAM_NODE);
if ($path && $path !== self::NODE_ROOT) {
$path = $this->convertIdToPath($path);
if ($this->mediaDirectoryWrite->isDirectory($path) && 0 === strpos($path, $currentPath)) {
$currentPath = $this->mediaDirectoryWrite->getRelativePath($path);
}
}
$this->_currentPath = $currentPath;
}
return $this->_currentPath;
}
示例7: 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;
}