Esempio n. 1
0
 /**
  * This event is triggered before any HTTP request is handled.
  *
  * We use this to intercept GET calls to notification nodes, and return the
  * proper response.
  *
  * @param string $method
  * @param string $path
  * @return void
  */
 public function beforeMethod($method, $path)
 {
     if ($method !== 'GET') {
         return;
     }
     try {
         $node = $this->server->tree->getNodeForPath($path);
     } catch (DAV\Exception\NotFound $e) {
         return;
     }
     if (!$node instanceof Notifications\INode) {
         return;
     }
     if (!$this->server->checkPreconditions(true)) {
         return false;
     }
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->formatOutput = true;
     $root = $dom->createElement('cs:notification');
     foreach ($this->server->xmlNamespaces as $namespace => $prefix) {
         $root->setAttribute('xmlns:' . $prefix, $namespace);
     }
     $dom->appendChild($root);
     $node->getNotificationType()->serializeBody($this->server, $root);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml');
     $this->server->httpResponse->setHeader('ETag', $node->getETag());
     $this->server->httpResponse->sendStatus(200);
     $this->server->httpResponse->sendBody($dom->saveXML());
     return false;
 }