public function deleteDocument(Request $request, TokenInfo $tokenInfo) { $path = new Path($request->getUrl()->getPathInfo()); if ($path->getUserId() !== $tokenInfo->getUserId()) { throw new ForbiddenException('path does not match authorized subject'); } if (!$this->hasWriteScope($tokenInfo->getScope(), $path->getModuleName())) { throw new ForbiddenException('path does not match authorized scope'); } // need to get the version before the delete $documentVersion = $this->remoteStorage->getVersion($path); $ifMatch = $this->stripQuotes($request->getHeader('If-Match')); // if document does not exist, and we have If-Match header set we should // return a 412 instead of a 404 if (null !== $ifMatch && !in_array($documentVersion, $ifMatch)) { throw new PreconditionFailedException('version mismatch'); } if (null === $documentVersion) { throw new NotFoundException(sprintf('document "%s" not found', $path->getPath())); } $ifMatch = $this->stripQuotes($request->getHeader('If-Match')); if (null !== $ifMatch && !in_array($documentVersion, $ifMatch)) { throw new PreconditionFailedException('version mismatch'); } $x = $this->remoteStorage->deleteDocument($path, $ifMatch); $rsr = new Response(); $rsr->setHeader('ETag', '"' . $documentVersion . '"'); $rsr->setBody($x); return $rsr; }