[Pkg-owncloud-commits] [php-sabredav] 47/148: moved free-busy-query to new xml system.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 4222728ec51c732dc6c2341b7ceeaa9848f3c2a8
Author: Evert Pot <me at evertpot.com>
Date:   Wed Feb 18 00:05:33 2015 -0500

    moved free-busy-query to new xml system.
---
 lib/CalDAV/Plugin.php                          | 44 ++++---------
 lib/CalDAV/Xml/Request/FreeBusyQueryReport.php | 91 ++++++++++++++++++++++++++
 tests/Sabre/CalDAV/FreeBusyReportTest.php      | 16 ++---
 3 files changed, 110 insertions(+), 41 deletions(-)

diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index 309ee00..bf721f3 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -180,6 +180,7 @@ class Plugin extends DAV\ServerPlugin {
 
         $server->xml->elementMap['{' . self::NS_CALDAV . '}calendar-query'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarQueryReport';
         $server->xml->elementMap['{' . self::NS_CALDAV . '}calendar-multiget'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarMultiGetReport';
+        $server->xml->elementMap['{' . self::NS_CALDAV . '}free-busy-query'] = 'Sabre\\CalDAV\\Xml\\Request\\FreeBusyQueryReport';
         $server->xml->elementMap['{' . self::NS_CALDAV . '}mkcalendar'] = 'Sabre\\CalDAV\\Xml\\Request\\MkCalendar';
 
         $server->resourceTypeMapping['\\Sabre\\CalDAV\\ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar';
@@ -216,23 +217,23 @@ class Plugin extends DAV\ServerPlugin {
      * This functions handles REPORT requests specific to CalDAV
      *
      * @param string $reportName
-     * @param \DOMNode $dom
+     * @param mixed $report
      * @return bool
      */
-    function report($reportName,$dom) {
+    function report($reportName, $report) {
 
         switch($reportName) {
             case '{' . self::NS_CALDAV . '}calendar-multiget' :
                 $this->server->transactionType = 'report-calendar-multiget';
-                $this->calendarMultiGetReport($dom);
+                $this->calendarMultiGetReport($report);
                 return false;
             case '{' . self::NS_CALDAV . '}calendar-query' :
                 $this->server->transactionType = 'report-calendar-query';
-                $this->calendarQueryReport($dom);
+                $this->calendarQueryReport($report);
                 return false;
             case '{' . self::NS_CALDAV . '}free-busy-query' :
                 $this->server->transactionType = 'report-free-busy-query';
-                $this->freeBusyQueryReport($dom);
+                $this->freeBusyQueryReport($report);
                 return false;
 
         }
@@ -599,35 +600,12 @@ class Plugin extends DAV\ServerPlugin {
      * This method is responsible for parsing the request and generating the
      * response for the CALDAV:free-busy-query REPORT.
      *
-     * @param \DOMNode $dom
+     * @param Xml\Request\FreeBusyQueryReport $report
      * @return void
      */
-    protected function freeBusyQueryReport(\DOMNode $dom) {
-
-        $start = null;
-        $end = null;
-
-        foreach($dom->firstChild->childNodes as $childNode) {
-
-            $clark = DAV\XMLUtil::toClarkNotation($childNode);
-            if ($clark == '{' . self::NS_CALDAV . '}time-range') {
-                $start = $childNode->getAttribute('start');
-                $end = $childNode->getAttribute('end');
-                break;
-            }
-
-        }
-        if ($start) {
-            $start = VObject\DateTimeParser::parseDateTime($start);
-        }
-        if ($end) {
-            $end = VObject\DateTimeParser::parseDateTime($end);
-        }
+    protected function freeBusyQueryReport(Xml\Request\FreeBusyQueryReport $report) {
 
         $uri = $this->server->getRequestUri();
-        if (!$start && !$end) {
-            throw new DAV\Exception\BadRequest('The freebusy report must have a time-range filter');
-        }
 
         $acl = $this->server->getPlugin('acl');
         if ($acl) {
@@ -663,8 +641,8 @@ class Plugin extends DAV\ServerPlugin {
                     'prop-filters' => [],
                     'is-not-defined' => false,
                     'time-range' => [
-                        'start' => $start,
-                        'end' => $end,
+                        'start' => $report->start,
+                        'end' => $report->end,
                     ],
                 ],
             ],
@@ -680,7 +658,7 @@ class Plugin extends DAV\ServerPlugin {
 
         $generator = new VObject\FreeBusyGenerator();
         $generator->setObjects($objects);
-        $generator->setTimeRange($start, $end);
+        $generator->setTimeRange($report->start, $report->end);
         $generator->setTimeZone($calendarTimeZone);
         $result = $generator->getResult();
         $result = $result->serialize();
diff --git a/lib/CalDAV/Xml/Request/FreeBusyQueryReport.php b/lib/CalDAV/Xml/Request/FreeBusyQueryReport.php
new file mode 100644
index 0000000..d50570e
--- /dev/null
+++ b/lib/CalDAV/Xml/Request/FreeBusyQueryReport.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Request;
+
+use Sabre\CalDAV\Plugin;
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\VObject\DateTimeParser;
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+
+/**
+ * FreeBusyQueryReport
+ *
+ * This class parses the {DAV:}free-busy-query REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc3253#section-3.8
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class FreeBusyQueryReport implements XmlDeserializable {
+
+    /**
+     * Starttime of report
+     *
+     * @var DateTime|null
+     */
+    public $start;
+
+    /**
+     * End time of report
+     *
+     * @var DateTime|null
+     */
+    public $end;
+
+    /**
+     * The deserialize method is called during xml parsing.
+     *
+     * This method is called statictly, this is because in theory this method
+     * may be used as a type of constructor, or factory method.
+     *
+     * Often you want to return an instance of the current class, but you are
+     * free to return other data as well.
+     *
+     * You are responsible for advancing the reader to the next element. Not
+     * doing anything will result in a never-ending loop.
+     *
+     * If you just want to skip parsing for this element altogether, you can
+     * just call $reader->next();
+     *
+     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+     * the next element.
+     *
+     * @param Reader $reader
+     * @return mixed
+     */
+    static function xmlDeserialize(Reader $reader) {
+
+        $timeRange = '{' . Plugin::NS_CALDAV . '}time-range';
+
+        $start = null;
+        $end = null;
+
+        foreach((array)$reader->parseInnerTree([]) as $elem) {
+
+            if ($elem['name']!==$timeRange) continue;
+
+            $start = empty($elem['attributes']['start'])?:$elem['attributes']['start'];
+            $end = empty($elem['attributes']['end'])?:$elem['attributes']['end'];
+
+        }
+        if (!$start && !$end) {
+            throw new BadRequest('The freebusy report must have a time-range element');
+        }
+        if ($start) {
+            $start = DateTimeParser::parseDateTime($start);
+        }
+        if ($end) {
+            $end = DateTimeParser::parseDateTime($end);
+        }
+        $result = new self();
+        $result->start = $start;
+        $result->end = $end;
+
+        return $result;
+
+    }
+
+}
diff --git a/tests/Sabre/CalDAV/FreeBusyReportTest.php b/tests/Sabre/CalDAV/FreeBusyReportTest.php
index 04a5031..2da2288 100644
--- a/tests/Sabre/CalDAV/FreeBusyReportTest.php
+++ b/tests/Sabre/CalDAV/FreeBusyReportTest.php
@@ -104,8 +104,8 @@ ics;
 </c:free-busy-query>
 XML;
 
-        $dom = DAV\XMLUtil::loadDOMDocument($reportXML);
-        $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
+        $report = $this->server->xml->parse($reportXML);
+        $this->plugin->report($report['name'], $report['value']);
 
         $this->assertEquals(200, $this->server->httpResponse->status);
         $this->assertEquals('text/calendar', $this->server->httpResponse->getHeader('Content-Type'));
@@ -126,8 +126,8 @@ XML;
 </c:free-busy-query>
 XML;
 
-        $dom = DAV\XMLUtil::loadDOMDocument($reportXML);
-        $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
+        $report = $this->server->xml->parse($reportXML);
+        $this->plugin->report($report['name'], $report['value']);
 
     }
 
@@ -148,8 +148,8 @@ XML;
 </c:free-busy-query>
 XML;
 
-        $dom = DAV\XMLUtil::loadDOMDocument($reportXML);
-        $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
+        $report = $this->server->xml->parse($reportXML);
+        $this->plugin->report($report['name'], $report['value']);
 
     }
 
@@ -169,8 +169,8 @@ XML;
 </c:free-busy-query>
 XML;
 
-        $dom = DAV\XMLUtil::loadDOMDocument($reportXML);
-        $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
+        $report = $this->server->xml->parse($reportXML);
+        $this->plugin->report($report['name'], $report['value']);
 
     }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list