[Pkg-owncloud-commits] [php-sabredav] 67/148: Moved sharing plugin to new xml system.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:16 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 43423d579dd7b9b62f9231a003ea14d08299c647
Author: Evert Pot <me at evertpot.com>
Date:   Wed Mar 18 19:18:36 2015 -0400

    Moved sharing plugin to new xml system.
---
 lib/CalDAV/SharingPlugin.php           | 113 ++++-----------------------------
 lib/CalDAV/Xml/Request/InviteReply.php |  25 ++++----
 lib/CalDAV/Xml/Request/Share.php       |  14 ++--
 tests/Sabre/DAV/XMLUtilTest.php        |   6 +-
 4 files changed, 40 insertions(+), 118 deletions(-)

diff --git a/lib/CalDAV/SharingPlugin.php b/lib/CalDAV/SharingPlugin.php
index faae5fc..c8a072b 100644
--- a/lib/CalDAV/SharingPlugin.php
+++ b/lib/CalDAV/SharingPlugin.php
@@ -92,6 +92,9 @@ class SharingPlugin extends DAV\ServerPlugin {
             '{' . Plugin::NS_CALENDARSERVER . '}shared-url'
         );
 
+        $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share';
+        $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply';
+
         $this->server->on('propFind',     [$this,'propFindEarly']);
         $this->server->on('propFind',     [$this,'propFindLate'], 150);
         $this->server->on('propPatch',    [$this, 'propPatch'], 40);
@@ -260,9 +263,12 @@ class SharingPlugin extends DAV\ServerPlugin {
         // re-populated the request body with the existing data.
         $request->setBody($requestBody);
 
-        $dom = DAV\XMLUtil::loadDOMDocument($requestBody);
+        $result = $this->server->xml->parse($requestBody);
+
+        $documentType = $result['name'];
+        $message = $result['value'];
 
-        $documentType = DAV\XMLUtil::toClarkNotation($dom->firstChild);
+        unset($result);
 
         switch($documentType) {
 
@@ -285,9 +291,7 @@ class SharingPlugin extends DAV\ServerPlugin {
                     $acl->checkPrivileges($path, '{DAV:}write');
                 }
 
-                $mutations = $this->parseShareRequest($dom);
-
-                $node->updateShares($mutations[0], $mutations[1]);
+                $node->updateShares($message->set, $message->remove);
 
                 $response->setStatus(200);
                 // Adding this because sending a response body may cause issues,
@@ -315,14 +319,12 @@ class SharingPlugin extends DAV\ServerPlugin {
                     $acl->checkPrivileges($path, '{DAV:}write');
                 }
 
-                $message = $this->parseInviteReplyRequest($dom);
-
                 $url = $node->shareReply(
-                    $message['href'],
-                    $message['status'],
-                    $message['calendarUri'],
-                    $message['inReplyTo'],
-                    $message['summary']
+                    $message->href,
+                    $message->status,
+                    $message->calendarUri,
+                    $message->inReplyTo,
+                    $message->summary
                 );
 
                 $response->setStatus(200);
@@ -406,93 +408,6 @@ class SharingPlugin extends DAV\ServerPlugin {
     }
 
     /**
-     * Parses the 'share' POST request.
-     *
-     * This method returns an array, containing two arrays.
-     * The first array is a list of new sharees. Every element is a struct
-     * containing a:
-     *   * href element. (usually a mailto: address)
-     *   * commonName element (often a first and lastname, but can also be
-     *     false)
-     *   * readOnly (true or false)
-     *   * summary (A description of the share, can also be false)
-     *
-     * The second array is a list of sharees that are to be removed. This is
-     * just a simple array with 'hrefs'.
-     *
-     * @param \DOMDocument $dom
-     * @return array
-     */
-    function parseShareRequest(\DOMDocument $dom) {
-
-        $xpath = new \DOMXPath($dom);
-        $xpath->registerNamespace('cs', Plugin::NS_CALENDARSERVER);
-        $xpath->registerNamespace('d', 'urn:DAV');
-
-        $set = [];
-        $elems = $xpath->query('cs:set');
-
-        for($i=0; $i < $elems->length; $i++) {
-
-            $xset = $elems->item($i);
-            $set[] = [
-                'href' => $xpath->evaluate('string(d:href)', $xset),
-                'commonName' => $xpath->evaluate('string(cs:common-name)', $xset),
-                'summary' => $xpath->evaluate('string(cs:summary)', $xset),
-                'readOnly' => $xpath->evaluate('boolean(cs:read)', $xset)!==false
-            ];
-
-        }
-
-        $remove = [];
-        $elems = $xpath->query('cs:remove');
-
-        for($i=0; $i < $elems->length; $i++) {
-
-            $xremove = $elems->item($i);
-            $remove[] = $xpath->evaluate('string(d:href)', $xremove);
-
-        }
-
-        return [$set, $remove];
-
-    }
-
-    /**
-     * Parses the 'invite-reply' POST request.
-     *
-     * This method returns an array, containing the following properties:
-     *   * href - The sharee who is replying
-     *   * status - One of the self::STATUS_* constants
-     *   * calendarUri - The url of the shared calendar
-     *   * inReplyTo - The unique id of the share invitation.
-     *   * summary - Optional description of the reply.
-     *
-     * @param \DOMDocument $dom
-     * @return array
-     */
-    function parseInviteReplyRequest(\DOMDocument $dom) {
-
-        $xpath = new \DOMXPath($dom);
-        $xpath->registerNamespace('cs', Plugin::NS_CALENDARSERVER);
-        $xpath->registerNamespace('d', 'urn:DAV');
-
-        $hostHref = $xpath->evaluate('string(cs:hosturl/d:href)');
-        if (!$hostHref) {
-            throw new DAV\Exception\BadRequest('The {' . Plugin::NS_CALENDARSERVER . '}hosturl/{DAV:}href element is required');
-        }
-
-        return [
-            'href' => $xpath->evaluate('string(d:href)'),
-            'calendarUri' => $this->server->calculateUri($hostHref),
-            'inReplyTo' => $xpath->evaluate('string(cs:in-reply-to)'),
-            'summary' => $xpath->evaluate('string(cs:summary)'),
-            'status' => $xpath->evaluate('boolean(cs:invite-accepted)')?self::STATUS_ACCEPTED:self::STATUS_DECLINED
-        ];
-
-    }
-
-    /**
      * Returns a bunch of meta-data about the plugin.
      *
      * Providing this information is optional, and is mainly displayed by the
diff --git a/lib/CalDAV/Xml/Request/InviteReply.php b/lib/CalDAV/Xml/Request/InviteReply.php
index 6f5129b..ba0e8df 100644
--- a/lib/CalDAV/Xml/Request/InviteReply.php
+++ b/lib/CalDAV/Xml/Request/InviteReply.php
@@ -2,12 +2,13 @@
 
 namespace Sabre\CalDAV\Xml\Request;
 
-use Sabre\Xml\Writer;
-use Sabre\Xml\XmlDeserializable;
-use Sabre\Xml\Element\KeyValue;
-use Sabre\DAV\Exception\BadRequest;
-use Sabre\CalDAV\Plugin;
-use Sabre\CalDAV\SharingPlugin;
+use
+    Sabre\Xml\Reader,
+    Sabre\Xml\XmlDeserializable,
+    Sabre\Xml\Element\KeyValue,
+    Sabre\DAV\Exception\BadRequest,
+    Sabre\CalDAV\Plugin,
+    Sabre\CalDAV\SharingPlugin;
 
 /**
  * Invite-reply POST request parser
@@ -16,11 +17,11 @@ use Sabre\CalDAV\SharingPlugin;
  *
  * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt
  *
- * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://www.rooftopsolutions.nl/)
- * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ * @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 InviteReply implements Element {
+class InviteReply implements XmlDeserializable {
 
     /**
      * The sharee calendar user address.
@@ -68,7 +69,7 @@ class InviteReply implements Element {
      * @param string $summary
      * @param int $status
      */
-    public function __construct($href, $calendarUri, $inReplyTo, $summary, $status) {
+    function __construct($href, $calendarUri, $inReplyTo, $summary, $status) {
 
         $this->href = $href;
         $this->calendarUri = $calendarUri;
@@ -101,7 +102,7 @@ class InviteReply implements Element {
      */
     static function xmlDeserialize(Reader $reader) {
 
-        $elems = KeyValue::deserializeXml($reader);
+        $elems = KeyValue::xmlDeserialize($reader);
 
         $href = null;
         $calendarUri = null;
diff --git a/lib/CalDAV/Xml/Request/Share.php b/lib/CalDAV/Xml/Request/Share.php
index 0242a58..d91e326 100644
--- a/lib/CalDAV/Xml/Request/Share.php
+++ b/lib/CalDAV/Xml/Request/Share.php
@@ -13,9 +13,9 @@ use Sabre\CalDAV\Plugin;
  *
  * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt
  *
- * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://www.rooftopsolutions.nl/)
- * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ * @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 Share implements XmlDeserializable {
 
@@ -75,11 +75,15 @@ class Share implements XmlDeserializable {
      * @param Reader $reader
      * @return mixed
      */
-    static function deserializeXml(Reader $reader) {
+    static function xmlDeserialize(Reader $reader) {
 
-        $elems = $reader->parseInnerTree();
+        $elems = $reader->parseInnerTree([
+            '{' . Plugin::NS_CALENDARSERVER . '}set' => 'Sabre\\Xml\\Element\\KeyValue',
+            '{' . Plugin::NS_CALENDARSERVER . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
+        ]);
 
         $set = [];
+        $remove = [];
 
         foreach($elems as $elem) {
             switch($elem['name']) {
diff --git a/tests/Sabre/DAV/XMLUtilTest.php b/tests/Sabre/DAV/XMLUtilTest.php
index 3a80fb0..ef152ea 100644
--- a/tests/Sabre/DAV/XMLUtilTest.php
+++ b/tests/Sabre/DAV/XMLUtilTest.php
@@ -124,7 +124,7 @@ class XMLUtilTest extends \PHPUnit_Framework_TestCase {
 
     /**
      * @expectedException Sabre\DAV\Exception\BadRequest
-     * @depends testConvertDAVNamespace
+     * @depends testLoadDOMDocument
      */
     function testLoadDOMDocumentInvalid() {
 
@@ -145,7 +145,9 @@ class XMLUtilTest extends \PHPUnit_Framework_TestCase {
 
     }
 
-
+    /**
+     * @depends testLoadDOMDocument
+     */
     function testParseProperties() {
 
         $xml='<?xml version="1.0"?>

-- 
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