Jyxo\Webdav\Client::getProperty PHP Method

getProperty() public method

If no particular property is set, all properties are returned.
public getProperty ( string $path, string $property = null ) : mixed
$path string File path
$property string Property name
return mixed
    public function getProperty(string $path, string $property = null)
    {
        // Asking random server
        $path = $this->getFilePath($path);
        $response = $this->sendRequest($path, self::METHOD_PROPFIND, ['Depth' => '0']);
        if (self::STATUS_207_MULTI_STATUS !== $response->getStatusCode()) {
            throw new FileNotExistException(sprintf('File %s does not exist.', $path));
        }
        // Fetches file properties from the server
        $properties = $this->getProperties($response);
        // Returns the requested property value
        if ($property !== null && isset($properties[$property])) {
            return $properties[$property];
        }
        // Returns all properties
        return $properties;
    }

Usage Example

Example #1
0
 /**
  * Tests retrieving file properties if the file does not exist.
  *
  * @depends testMkdir
  */
 public function testGetPropertyIfFileNotExist()
 {
     $this->setExpectedException('\\Jyxo\\Webdav\\FileNotExistException');
     $this->client->getProperty($this->dir . '/dummy.txt');
 }