public function FileSystem::mkdir in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::mkdir()
- 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::mkdir()
File
- core/lib/Drupal/Core/File/FileSystem.php, line 180
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\File
Code
public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
if (!isset($mode)) {
$mode = $this->settings
->get('file_chmod_directory', static::CHMOD_DIRECTORY);
}
if (StreamWrapperManager::getScheme($uri)) {
return $this
->mkdirCall($uri, $mode, $recursive, $context);
}
if ($recursive) {
$uri = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $uri), DIRECTORY_SEPARATOR);
$components = explode(DIRECTORY_SEPARATOR, $uri);
if ($components[0] == '') {
$recursive_path = DIRECTORY_SEPARATOR;
array_shift($components);
}
else {
$recursive_path = '';
}
array_pop($components);
foreach ($components as $component) {
$recursive_path .= $component;
if (!file_exists($recursive_path)) {
$success = $this
->mkdirCall($recursive_path, $mode, FALSE, $context);
if (!$success && !file_exists($recursive_path)) {
return FALSE;
}
if (!chmod($recursive_path, $mode)) {
return FALSE;
}
}
$recursive_path .= DIRECTORY_SEPARATOR;
}
}
if (!$this
->mkdirCall($uri, $mode, FALSE, $context)) {
return FALSE;
}
return chmod($uri, $mode);
}