Jyxo\Webdav\Client::unlink PHP Method

    public function unlink(string $path)
    {
        // We do not delete directories
        if ($this->isDir($path)) {
            throw new FileNotDeletedException(sprintf('The path %s is a directory.', $path));
        }
        foreach ($this->sendAllRequests($this->createAllRequests($this->getFilePath($path), self::METHOD_DELETE)) as $response) {
            switch ($response->getStatusCode()) {
                case self::STATUS_200_OK:
                case self::STATUS_204_NO_CONTENT:
                    // Means deleted
                // Means deleted
                case self::STATUS_404_NOT_FOUND:
                    break;
                default:
                    throw new FileNotDeletedException(sprintf('File %s cannot be deleted.', $path));
            }
        }
    }

Usage Example

Example #1
0
 /**
  * Tests deleting a file.
  *
  * @depends testIsDir
  * @depends testGet
  * @depends testGetProperty
  * @depends testGetPropertyIfFileNotExist
  */
 public function testUnlink()
 {
     $this->assertTrue($this->client->unlink($this->file));
     $this->assertFalse($this->client->unlink($this->dir . '/dummy.txt'));
     // The function must return false if a directory name is given
     $this->assertFalse($this->client->unlink($this->dir));
 }