protected function processPut(string $path, string $data, bool $isFile)
{
$requests = [];
foreach ($this->servers as $server) {
$body = $isFile ? fopen($data, 'r') : $data;
$requests[$server] = $this->createRequest($server, $path, self::METHOD_PUT, [], $body);
}
$success = true;
foreach ($this->sendAllRequests($requests) as $response) {
switch ($response->getStatusCode()) {
// Saved
case self::STATUS_200_OK:
case self::STATUS_201_CREATED:
break;
// An existing file was modified
// An existing file was modified
case self::STATUS_204_NO_CONTENT:
break;
// The directory might not exist
// The directory might not exist
case self::STATUS_403_FORBIDDEN:
case self::STATUS_404_NOT_FOUND:
case self::STATUS_409_CONFLICT:
$success = false;
break;
// Could not save
// Could not save
default:
throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path));
}
}
// Saved
if ($success) {
return;
}
// Not saved, try creating the directory first
if ($this->createDirectoriesAutomatically) {
try {
$this->mkdir(dirname($path));
} catch (DirectoryNotCreatedException $e) {
throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path), 0, $e);
}
}
// Try again
foreach ($this->sendAllRequests($requests) as $response) {
// 201 means saved
if (self::STATUS_201_CREATED !== $response->getStatusCode()) {
throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path));
}
}
}