public function mkdir(string $dir, bool $recursive = true)
{
// If creating directories recursively, create the parent directory first
$dir = trim($dir, '/');
if ($recursive) {
$dirs = explode('/', $dir);
} else {
$dirs = [$dir];
}
$path = '';
foreach ($dirs as $dir) {
$path .= rtrim($dir);
$path = $this->getDirPath($path);
foreach ($this->sendAllRequests($this->createAllRequests($path, self::METHOD_MKCOL)) as $response) {
switch ($response->getStatusCode()) {
// The directory was created
case self::STATUS_201_CREATED:
break;
// The directory already exists
// The directory already exists
case self::STATUS_405_METHOD_NOT_ALLOWED:
break;
// The directory could not be created
// The directory could not be created
default:
throw new DirectoryNotCreatedException(sprintf('Directory %s cannot be created.', $path));
}
}
}
}