Ejemplo n.º 1
0
 /**
  * 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 unsupported mkcol bodies
             throw new Exception\UnsupportedMediaType('The request body for the MKCOL request must have an xml Content-Type');
         }
         $dom = XMLUtil::loadDOMDocument($requestBody);
         if (XMLUtil::toClarkNotation($dom->firstChild) !== '{DAV:}mkcol') {
             // We must throw 415 for unsupported mkcol bodies
             throw new 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 (XMLUtil::toClarkNotation($childNode) !== '{DAV:}set') {
                 continue;
             }
             $properties = array_merge($properties, XMLUtil::parseProperties($childNode, $this->propertyMap));
         }
         if (!isset($properties['{DAV:}resourcetype'])) {
             throw new Exception\BadRequest('The mkcol request must include a {DAV:}resourcetype property');
         }
         $resourceType = $properties['{DAV:}resourcetype']->getValue();
         unset($properties['{DAV:}resourcetype']);
     } 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);
     }
 }