Jyxo\Webdav\Client::isDir PHP Method

isDir() public method

Checks if a directory exists.
public isDir ( string $dir ) : boolean
$dir string Directory path
return boolean
    public function isDir(string $dir) : bool
    {
        // Asking random server
        $response = $this->sendRequest($this->getDirPath($dir), self::METHOD_PROPFIND, ['Depth' => '0']);
        // The directory does not exist or server does not support PROPFIND method
        if (self::STATUS_207_MULTI_STATUS !== $response->getStatusCode()) {
            return false;
        }
        // Fetches properties from the server
        $properties = $this->getProperties($response);
        // Checks if it is a directory
        return isset($properties['getcontenttype']) && 'httpd/unix-directory' === $properties['getcontenttype'];
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Tests directory existence.
  *
  * @depends testMkdir
  * @depends testPut
  */
 public function testIsDir()
 {
     $this->assertTrue($this->client->isDir($this->dir));
     $this->assertFalse($this->client->isDir('dummy'));
     // The function must return false for files
     $this->assertFalse($this->client->isDir($this->file));
 }