Skip to content

Commit

Permalink
Add event to allow inspecting and changing multipart responses
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Aug 26, 2018
1 parent de8a4c9 commit 190e42c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ function getResourceTypeForNode(INode $node) {
* @return string
*/
function generateMultiStatus($fileProperties, $strip404s = false) {
$this->emit('beforeMultiStatus', [&$fileProperties]);

$w = $this->xml->getWriter();
$w->openMemory();
Expand Down
37 changes: 37 additions & 0 deletions tests/Sabre/DAV/ServerEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ServerEventsTest extends AbstractServer {

private $exception;

private $fileProperties;

function testAfterBind() {

$this->server->on('afterBind', [$this, 'afterBindHandler']);
Expand Down Expand Up @@ -123,4 +125,39 @@ function testMethod() {

}

function multiStatusHandler(&$fileProperties) {
$this->fileProperties = $fileProperties;
$fileProperties = array_slice($fileProperties, 0, 1);
}

function testBeforeMultiStatus() {

$this->server->on('beforeMultiStatus', [$this, 'multiStatusHandler']);

$response = $this->server->generateMultiStatus([
[
'href' => 'foo',
'200' => [
'd:getcontentlength' => 10
],
],
[
'href' => 'bar',
'200' => [
'd:getcontentlength' => 11
],
]
]);

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $response);
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');

$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength');
$this->assertCount(1, $data);

$this->assertCount(2, $this->fileProperties);

}

}

0 comments on commit 190e42c

Please sign in to comment.