public function rename(string $pathFrom, string $pathTo)
{
$pathTo = $this->getFilePath($pathTo);
// Try creating the directory first
if ($this->createDirectoriesAutomatically) {
try {
$this->mkdir(dirname($pathTo));
} catch (DirectoryNotCreatedException $e) {
throw new FileNotRenamedException(sprintf('File %s cannot be renamed to %s.', $pathFrom, $pathTo), 0, $e);
}
}
$requests = [];
foreach ($this->servers as $server) {
$requests[$server] = $this->createRequest($server, $this->getFilePath($pathFrom), self::METHOD_MOVE, ['Destination' => $server . $pathTo]);
}
foreach ($this->sendAllRequests($requests) as $response) {
switch ($response->getStatusCode()) {
case self::STATUS_201_CREATED:
case self::STATUS_204_NO_CONTENT:
// Means renamed
break;
default:
throw new FileNotRenamedException(sprintf('File %s cannot be renamed to %s.', $pathFrom, $pathTo));
}
}
}