Skip to content

Commit

Permalink
Sabre\DAV\Server::generateMultiStatus: return a callback outputting t…
Browse files Browse the repository at this point in the history
…he multi-status
  • Loading branch information
Petr Kotek authored and petrkotek committed Oct 16, 2016
1 parent 54ece84 commit b6727b4
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,42 +1645,43 @@ function getResourceTypeForNode(INode $node) {


/**
* Generates a WebDAV propfind response body based on a list of nodes.
* Returns a callback generating a WebDAV propfind response body based on a list of nodes.
*
* If 'strip404s' is set to true, all 404 responses will be removed.
*
* @param array|\Traversable $fileProperties The list with nodes
* @param bool $strip404s
* @return string
* @return callable
*/
function generateMultiStatus($fileProperties, $strip404s = false) {

$w = $this->xml->getWriter();
$w->openMemory();
$w->contextUri = $this->baseUri;
$w->startDocument();

$w->startElement('{DAV:}multistatus');

foreach ($fileProperties as $entry) {

$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
return function() use ($fileProperties, $strip404s, $w) {
$w->openUri('php://output');
$w->contextUri = $this->baseUri;
$w->startDocument();

$w->startElement('{DAV:}multistatus');

foreach ($fileProperties as $entry) {
$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response
]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response
]);
}
$w->endElement();

return $w->outputMemory();
$w->endElement();
$w->endDocument();
$w->flush();
};

}

Expand Down

0 comments on commit b6727b4

Please sign in to comment.