/** * WebDAV PROPPATCH * * This method is called to update properties on a Node. The request is an XML body with all the mutations. * In this XML body it is specified which properties should be set/updated and/or deleted * * @return void */ protected function httpPropPatch() { $mutations = $this->parsePropPatchRequest($this->httpRequest->getBody(true)); $node = $this->tree->getNodeForPath($this->getRequestUri()); if ($node instanceof Sabre_DAV_IProperties) { $result = $node->updateProperties($mutations); } else { $result = array(); foreach ($mutations as $mutations) { $result[] = array($mutations[1], 403); } } $this->httpResponse->sendStatus(207); $this->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); // Re-arranging result for generateMultiStatus $multiStatusResult = array(); foreach ($result as $row) { if (!isset($multiStatusResult[$row[1]])) { $multiStatusResult[$row[1]] = array(); } $multiStatusResult[$row[1]][$row[0]] = null; } $multiStatusResult['href'] = $this->getRequestUri(); $multiStatusResult = array($multiStatusResult); $this->httpResponse->sendBody($this->generateMultiStatus($multiStatusResult)); }
function testSendBodyStream() { ob_start(); $stream = fopen('php://memory', 'r+'); fwrite($stream, 'hello'); rewind($stream); $response = new Sabre_HTTP_Response(); $response->sendBody($stream); $this->assertEquals('hello', ob_get_clean()); }
/** * WebDAV MKCOL * * The MKCOL method is used to create a new collection (directory) on the server * * @param string $uri * @return void */ protected function httpMkcol($uri) { $requestBody = $this->httpRequest->getBody(true); if ($requestBody) { $contentType = $this->httpRequest->getHeader('Content-Type'); if (strpos($contentType, 'application/xml') !== 0 && strpos($contentType, 'text/xml') !== 0) { // We must throw 415 for unsupport mkcol bodies throw new Sabre_DAV_Exception_UnsupportedMediaType('The request body for the MKCOL request must have an xml Content-Type'); } $dom = Sabre_DAV_XMLUtil::loadDOMDocument($requestBody); if (Sabre_DAV_XMLUtil::toClarkNotation($dom->firstChild) !== '{DAV:}mkcol') { // We must throw 415 for unsupport mkcol bodies throw new Sabre_DAV_Exception_UnsupportedMediaType('The request body for the MKCOL request must be a {DAV:}mkcol request construct.'); } $properties = array(); foreach ($dom->firstChild->childNodes as $childNode) { if (Sabre_DAV_XMLUtil::toClarkNotation($childNode) !== '{DAV:}set') { continue; } $properties = array_merge($properties, Sabre_DAV_XMLUtil::parseProperties($childNode, $this->propertyMap)); } if (!isset($properties['{DAV:}resourcetype'])) { throw new Sabre_DAV_Exception_BadRequest('The mkcol request must include a {DAV:}resourcetype property'); } /*noLibHook*/ unset($properties['{DAV:}resourcetype']); $resourceType = array(); // Need to parse out all the resourcetypes $rtNode = $dom->firstChild->getElementsByTagNameNS('urn:DAV', 'resourcetype'); $rtNode = $rtNode->item(0); foreach ($rtNode->childNodes as $childNode) { $resourceType[] = Sabre_DAV_XMLUtil::toClarkNotation($childNode); } } else { $properties = array(); $resourceType = array('{DAV:}collection'); } $result = $this->createCollection($uri, $resourceType, $properties); if (is_array($result)) { $this->httpResponse->sendStatus(207); $this->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->httpResponse->sendBody($this->generateMultiStatus(array($result))); } else { $this->httpResponse->setHeader('Content-Length', '0'); $this->httpResponse->sendStatus(201); } }