/** * Constructor. * @param int $status the HTTP/1.1 status code, defaults to DAV::HTTP_INTERNAL_SERVER_ERROR * @param mixed $info One of the following: * - for a 3xx status: the URL of the Location: response header * - for a 4xx status: either * - an array of pre- or postconditions, with the conditions as keys and extra XML as values * - a free error string * - for a 5xx status: a free error string */ public function __construct($status = DAV::HTTP_INTERNAL_SERVER_ERROR, $info = null) { if ($status < 300) { // Do nothing special. } elseif ($status < 400) { $info = preg_split('@\\s+@', "{$info}", 2); if (!DAV::isValidURI($info[0])) { throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR, "No location URI for status {$status} " . var_export($info, true)); } $this->location = $info[0]; $info = @$info[1]; } elseif ($status < 500) { if (is_array($info)) { foreach ($info as $condition => $xml) { if (!isset(DAV::$CONDITIONS[$condition])) { throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR, "Invalid condition {$condition} with message " . var_export($message, true)); } } $this->conditions = $info; $info = null; } elseif (isset(DAV::$CONDITIONS[$info])) { $this->conditions = array($info => null); $info = null; } } parent::__construct("{$info}", $status); if ($status >= 500 && $status !== DAV::HTTP_NOT_IMPLEMENTED && $status !== DAV::HTTP_SERVICE_UNAVAILABLE) { trigger_error("{$info}\n{$this}", E_USER_WARNING); } }
public function testIsValidURI() { $this->assertTrue(DAV::isValidURI('http://webdav.org/some/path/to/a/file.txt'), 'DAV:isValidUri() should return true for a valid uri'); $this->assertFalse(DAV::isValidURI('@#$wrong_uri/but/with/path/t43#$'), 'DAV:isValidUri() should return false for an invalid uri'); }