Exemplo n.º 1
0
 protected function parseBody(HttpRequest $request)
 {
     $contents = $request->getContents();
     if ($contents === '') {
         throw new BadRequestException();
     }
     try {
         $xml = (new XmlDocumentBuilder())->buildFromSource($contents);
     } catch (XmlParseException $e) {
         throw new BadRequestException($e);
     }
     $root = $xml->documentElement;
     if ($root->namespaceURI != WebDav::NS_DAV || $root->localName != 'propertyupdate') {
         throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
     }
     $xpath = new \DOMXPath($xml);
     $xpath->registerNamespace('D', WebDav::NS_DAV);
     $proppatch = new ProppatchRequest();
     foreach ($xpath->query('/D:propertyupdate/*') as $el) {
         if ($el->namespaceURI != WebDav::NS_DAV) {
             throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
         }
         if ($el->localName == 'set') {
             $nodes = $xpath->query('D:prop/*', $el);
             if ($nodes->length < 1) {
                 throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
             }
             foreach ($nodes as $set) {
                 $proppatch->addOperation(new SetPropertyOperation(new XmlName($set), $set));
             }
         } elseif ($el->localName == 'remove') {
             $nodes = $xpath->query('D:prop/*', $el);
             if ($nodes->length < 1) {
                 throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
             }
             foreach ($nodes as $remove) {
                 $proppatch->addOperation(new RemovePropertyOperation(new XmlName($remove)));
             }
         } else {
             throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
         }
     }
     if ($proppatch->count() < 1) {
         throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
     }
     return $proppatch;
 }
Exemplo n.º 2
0
 protected function parseBody(HttpRequest $request)
 {
     if (!$request->hasEntity()) {
         return new AllPropRequest();
     }
     $contents = trim($request->getContents());
     if ($contents == '') {
         return new AllPropRequest();
     }
     try {
         $xml = (new XmlDocumentBuilder())->buildFromSource($contents);
     } catch (XmlParseException $e) {
         throw new BadRequestException($e);
     }
     $root = $xml->documentElement;
     if ($root->namespaceURI != WebDav::NS_DAV || $root->localName != 'propfind') {
         throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
     }
     $xpath = new \DOMXPath($xml);
     $xpath->registerNamespace('D', WebDav::NS_DAV);
     $nodes = $xpath->query('/D:propfind/D:*');
     if ($nodes->length == 0) {
         throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
     }
     $nodes = $xpath->query('/D:propfind/D:propname');
     if ($nodes->length == 1) {
         return new PropNameRequest();
     }
     $nodes = $xpath->query('/D:propfind/D:allprop');
     if ($nodes->length == 1) {
         return $this->parseAllPropRequest($nodes->item(0)->parentNode, $xpath);
     }
     $nodes = $xpath->query('/D:propfind/D:prop');
     if ($nodes->length > 0) {
         return $this->parsePropfindRequest($nodes, $xpath);
     }
     throw new WebDavException(WebDav::CODE_UNPROCESSABLE_ENTITY);
 }
Exemplo n.º 3
0
 protected function createLock(ResourceInterface $resource, Uri $baseUri, HttpRequest $request, LockStorageInterface $storage)
 {
     if (!$resource instanceof LockableResourceInterface || !$resource->isLockSupported()) {
         throw new MethodNotAllowedException();
     }
     $body = $request->getContents();
     if ($body === '') {
         return $this->refreshLock($resource, $baseUri, $request, $storage);
     }
     if ($resource->isLocked()) {
         throw new NoConflictingLockException([$request->getUri()]);
     }
     if ($request->hasHeader('Depth')) {
         if ('0' !== strtolower($request->getHeader('Depth', 'infinity'))) {
             throw new BadRequestException();
         }
     }
     $owner = $this->parseLockBody($body);
     $storage->beginTransaction();
     try {
         $lock = $storage->createLock($resource, $this->computeExpires($request), $owner);
     } catch (\Exception $e) {
         $storage->rollBack();
         throw $e;
     }
     $storage->commit();
     return $this->createLockResponse(WebDav::CODE_OK, $lock, $baseUri);
 }
Exemplo n.º 4
0
 public function handle($path, Uri $baseUri, HttpRequest $request, StorageInterface $storage)
 {
     if ($request->getMethod() != WebDav::METHOD_REPORT) {
         return;
     }
     try {
         $resource = $storage->findResource($path);
     } catch (\OutOfBoundsException $e) {
         throw new NotFoundException($e);
     }
     try {
         $xml = (new XmlDocumentBuilder())->buildFromSource($request->getContents());
     } catch (XmlParseException $e) {
         throw new BadRequestException($e);
     }
     $name = new XmlName($xml->documentElement);
     foreach ($this->generators as $generator) {
         if ($generator->getReportName() == $name && $generator->isSupported($resource)) {
             return $generator->generateReport($xml->documentElement, $resource, $baseUri, $request, $this->dispatcher);
         }
     }
     throw new UnsupportedReportException();
 }