Jyxo\Webdav\Client::rename PHP Method

rename() public method

Does not work on Lighttpd.
public rename ( string $pathFrom, string $pathTo )
$pathFrom string Original file name
$pathTo string New file name
    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));
            }
        }
    }

Usage Example

Example #1
0
 /**
  * Tests file renaming.
  *
  * @depends testPut
  */
 public function testRename()
 {
     // Lighttpd does not support this method.
     // $this->assertTrue($this->client->rename($this->file, $this->dir . '/testrename.txt'));
     $this->assertFalse($this->client->rename($this->dir . '/dummy.txt', $this->dir . '/dummyrename.txt'));
 }