本文整理汇总了PHP中Sabre_DAV_Server::checkPreconditions方法的典型用法代码示例。如果您正苦于以下问题:PHP Sabre_DAV_Server::checkPreconditions方法的具体用法?PHP Sabre_DAV_Server::checkPreconditions怎么用?PHP Sabre_DAV_Server::checkPreconditions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre_DAV_Server
的用法示例。
在下文中一共展示了Sabre_DAV_Server::checkPreconditions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeMethod
/**
* This event is triggered before any HTTP request is handled.
*
* We use this to intercept GET calls to notification nodes, and return the
* proper response.
*
* @param string $method
* @param string $path
* @return void
*/
public function beforeMethod($method, $path)
{
if ($method !== 'GET') {
return;
}
try {
$node = $this->server->tree->getNodeForPath($path);
} catch (Sabre_DAV_Exception_NotFound $e) {
return;
}
if (!$node instanceof Sabre_CalDAV_Notifications_INode) {
return;
}
if (!$this->server->checkPreconditions(true)) {
return false;
}
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('cs:notification');
foreach ($this->server->xmlNamespaces as $namespace => $prefix) {
$root->setAttribute('xmlns:' . $prefix, $namespace);
}
$dom->appendChild($root);
$node->getNotificationType()->serializeBody($this->server, $root);
$this->server->httpResponse->setHeader('Content-Type', 'application/xml');
$this->server->httpResponse->setHeader('ETag', $node->getETag());
$this->server->httpResponse->sendStatus(200);
$this->server->httpResponse->sendBody($dom->saveXML());
return false;
}
示例2: httpPatch
/**
* Patch an uri
*
* The WebDAV patch request can be used to modify only a part of an
* existing resource. If the resource does not exist yet and the first
* offset is not 0, the request fails
*
* @param string $uri
* @return void
*/
protected function httpPatch($uri)
{
// Get the node. Will throw a 404 if not found
$node = $this->server->tree->getNodeForPath($uri);
if (!$node instanceof Sabre_DAV_PartialUpdate_IFile) {
throw new Sabre_DAV_Exception_MethodNotAllowed('The target resource does not support the PATCH method.');
}
$range = $this->getHTTPUpdateRange();
if (!$range) {
throw new Sabre_DAV_Exception_BadRequest('No valid "X-Update-Range" found in the headers');
}
$contentType = strtolower($this->server->httpRequest->getHeader('Content-Type'));
if ($contentType != 'application/x-sabredav-partialupdate') {
throw new Sabre_DAV_Exception_UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
}
$len = $this->server->httpRequest->getHeader('Content-Length');
// Load the begin and end data
$start = $range[0] ? $range[0] : 0;
$end = $range[1] ? $range[1] : $len - 1;
// Check consistency
if ($end < $start) {
throw new Sabre_DAV_Exception_RequestedRangeNotSatisfiable('The end offset (' . $range[1] . ') is lower than the start offset (' . $range[0] . ')');
}
if ($end - $start + 1 != $len) {
throw new Sabre_DAV_Exception_RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[0] . ') and end (' . $range[1] . ') offsets');
}
// Checking If-None-Match and related headers.
if (!$this->server->checkPreconditions()) {
return;
}
if (!$this->server->broadcastEvent('beforeWriteContent', array($uri, $node, null))) {
return;
}
$body = $this->server->httpRequest->getBody();
$etag = $node->putRange($body, $start - 1);
$this->server->broadcastEvent('afterWriteContent', array($uri, $node));
$this->server->httpResponse->setHeader('Content-Length', '0');
if ($etag) {
$this->server->httpResponse->setHeader('ETag', $etag);
}
$this->server->httpResponse->sendStatus(204);
return false;
}
示例3: testIfUnmodifiedSinceInvalidDate
/**
* @covers Sabre_DAV_Server::checkPreconditions
*/
public function testIfUnmodifiedSinceInvalidDate()
{
$root = new Sabre_DAV_SimpleCollection('root', array(new Sabre_DAV_ServerPreconditionsNode()));
$server = new Sabre_DAV_Server($root);
$httpRequest = new Sabre_HTTP_Request(array('HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET', 'REQUEST_URI' => '/foo'));
$server->httpRequest = $httpRequest;
$server->httpResponse = new Sabre_HTTP_ResponseMock();
$this->assertTrue($server->checkPreconditions());
}