mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Dav: refactor WebdavController
This commit is contained in:
parent
6f6683f549
commit
3fe870ba71
@ -92,24 +92,7 @@ final readonly class WebdavController
|
||||
throw new BadRequestHttpException("only 1 and 0 are accepted for Depth header");
|
||||
}
|
||||
|
||||
$content = $request->getContent();
|
||||
$xml = new \DOMDocument();
|
||||
$xml->loadXML($content);
|
||||
|
||||
$properties = $this->requestAnalyzer->getRequestedProperties($xml);
|
||||
$requested = array_keys(array_filter($properties, fn ($item) => true === $item));
|
||||
|
||||
if (
|
||||
in_array('lastModified', $requested, true)
|
||||
|| in_array('etag', $requested, true)
|
||||
) {
|
||||
$lastModified = $this->storedObjectManager->getLastModified($storedObject);
|
||||
$etag = $this->storedObjectManager->etag($storedObject);
|
||||
|
||||
}
|
||||
if (in_array('contentLength', $requested, true)) {
|
||||
$length = $this->storedObjectManager->getContentLength($storedObject);
|
||||
}
|
||||
[$properties, $lastModified, $etag, $length] = $this->parseDavRequest($request->getContent(), $storedObject);
|
||||
|
||||
$response = new DavResponse(
|
||||
$this->engine->render('@ChillDocStore/Webdav/directory_propfind.xml.twig', [
|
||||
@ -185,23 +168,7 @@ final readonly class WebdavController
|
||||
*/
|
||||
public function propfindDocument(StoredObject $storedObject, string $access_token, Request $request): Response
|
||||
{
|
||||
$content = $request->getContent();
|
||||
$xml = new \DOMDocument();
|
||||
$xml->loadXML($content);
|
||||
|
||||
$properties = $this->requestAnalyzer->getRequestedProperties($xml);
|
||||
$requested = array_keys(array_filter($properties, fn ($item) => true === $item));
|
||||
|
||||
if (
|
||||
in_array('lastModified', $requested, true)
|
||||
|| in_array('etag', $requested, true)
|
||||
) {
|
||||
$lastModified = $this->storedObjectManager->getLastModified($storedObject);
|
||||
$etag = $this->storedObjectManager->etag($storedObject);
|
||||
}
|
||||
if (in_array('contentLength', $requested, true)) {
|
||||
$length = $this->storedObjectManager->getContentLength($storedObject);
|
||||
}
|
||||
[$properties, $lastModified, $etag, $length] = $this->parseDavRequest($request->getContent(), $storedObject);
|
||||
|
||||
$response = new DavResponse(
|
||||
$this->engine->render(
|
||||
@ -235,4 +202,34 @@ final readonly class WebdavController
|
||||
|
||||
return (new DavResponse("", Response::HTTP_NO_CONTENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: array, 1: DateTimeInterface, 2: string, 3: int} properties, lastModified, etag, length
|
||||
*/
|
||||
private function parseDavRequest(string $content, StoredObject $storedObject): array
|
||||
{
|
||||
$xml = new \DOMDocument();
|
||||
$xml->loadXML($content);
|
||||
|
||||
$properties = $this->requestAnalyzer->getRequestedProperties($xml);
|
||||
$requested = array_keys(array_filter($properties, fn ($item) => true === $item));
|
||||
|
||||
if (
|
||||
in_array('lastModified', $requested, true)
|
||||
|| in_array('etag', $requested, true)
|
||||
) {
|
||||
$lastModified = $this->storedObjectManager->getLastModified($storedObject);
|
||||
$etag = $this->storedObjectManager->etag($storedObject);
|
||||
}
|
||||
if (in_array('contentLength', $requested, true)) {
|
||||
$length = $this->storedObjectManager->getContentLength($storedObject);
|
||||
}
|
||||
|
||||
return [
|
||||
$properties,
|
||||
$lastModified ?? null,
|
||||
$etag ?? null,
|
||||
$length ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user