Example #1
0
 /**
  * Sends the response to a sync-collection request.
  *
  * @param string $syncToken
  * @param string $collectionUrl
  * @param array $added
  * @param array $modified
  * @param array $deleted
  * @param array $properties
  * @return void
  */
 protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $multiStatus = $dom->createElement('d:multistatus');
     $dom->appendChild($multiStatus);
     // Adding in default namespaces
     foreach ($this->server->xmlNamespaces as $namespace => $prefix) {
         $multiStatus->setAttribute('xmlns:' . $prefix, $namespace);
     }
     $fullPaths = [];
     // Pre-fetching children, if this is possible.
     foreach (array_merge($added, $modified) as $item) {
         $fullPath = $collectionUrl . '/' . $item;
         $fullPaths[] = $fullPath;
     }
     foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) {
         // The 'Property_Response' class is responsible for generating a
         // single {DAV:}response xml element.
         $response = new DAV\Property\Response($fullPath, $props);
         $response->serialize($this->server, $multiStatus);
     }
     // Deleted items also show up as 'responses'. They have no properties,
     // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'.
     foreach ($deleted as $item) {
         $fullPath = $collectionUrl . '/' . $item;
         $response = new DAV\Property\Response($fullPath, [], 404);
         $response->serialize($this->server, $multiStatus);
     }
     $syncToken = $dom->createElement('d:sync-token', self::SYNCTOKEN_PREFIX . $syncToken);
     $multiStatus->appendChild($syncToken);
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setBody($dom->saveXML());
 }
Example #2
0
 /**
  * Generates 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 $fileProperties The list with nodes
  * @param bool strip404s
  * @return string
  */
 function generateMultiStatus(array $fileProperties, $strip404s = false)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     //$dom->formatOutput = true;
     $multiStatus = $dom->createElement('d:multistatus');
     $dom->appendChild($multiStatus);
     // Adding in default namespaces
     foreach ($this->xmlNamespaces as $namespace => $prefix) {
         $multiStatus->setAttribute('xmlns:' . $prefix, $namespace);
     }
     foreach ($fileProperties as $entry) {
         $href = $entry['href'];
         unset($entry['href']);
         if ($strip404s && isset($entry[404])) {
             unset($entry[404]);
         }
         $response = new Property\Response($href, $entry);
         $response->serialize($this, $multiStatus);
     }
     return $dom->saveXML();
 }
Example #3
0
 /**
  * @depends testSerialize
  * @expectedException Sabre\DAV\Exception
  */
 function testSerializeBreak()
 {
     $innerProps = array(200 => array('{DAV:}link' => new \STDClass()));
     $property = new Response('uri', $innerProps);
     $doc = new \DOMDocument();
     $root = $doc->createElement('d:root');
     $root->setAttribute('xmlns:d', 'DAV:');
     $doc->appendChild($root);
     $server = new DAV\Server();
     $property->serialize($server, $root);
 }