[Pkg-owncloud-commits] [php-sabredav] 168/220: Parsing principal-match

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:23 UTC 2016


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

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

commit 820576c9e6c1ee2b08ffcb29712f732da59f6635
Author: Evert Pot <me at evertpot.com>
Date:   Mon Apr 18 17:31:49 2016 +0800

    Parsing principal-match
---
 lib/DAVACL/Plugin.php                              | 29 +++++++-
 lib/DAVACL/Xml/Request/PrincipalMatchReport.php    | 86 ++++++++++++++++++++++
 .../Xml/Request/PrincipalMatchReportTest.php       | 51 +++++++++++++
 3 files changed, 162 insertions(+), 4 deletions(-)

diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index f22d206..065d02c 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -164,6 +164,7 @@ class Plugin extends DAV\ServerPlugin {
 
         return [
             '{DAV:}expand-property',
+            '{DAV:}principal-match',
             '{DAV:}principal-property-search',
             '{DAV:}principal-search-property-set',
         ];
@@ -233,6 +234,7 @@ class Plugin extends DAV\ServerPlugin {
      */
     function getCurrentUserPrincipal() {
 
+        /** @var $authPlugin Sabre\DAV\Auth\Plugin */
         $authPlugin = $this->server->getPlugin('auth');
         if (!$authPlugin) {
             return null;
@@ -856,6 +858,7 @@ class Plugin extends DAV\ServerPlugin {
         $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
         $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
         $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport';
+        $server->xml->elementMap['{DAV:}principal-match'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalMatchReport';
 
     }
 
@@ -896,12 +899,10 @@ class Plugin extends DAV\ServerPlugin {
                 $this->checkPrivileges($path, '{DAV:}write-content');
                 break;
 
-
             case 'UNLOCK' :
                 // Unlock is always allowed at the moment.
                 break;
 
-
             case 'PROPPATCH' :
                 $this->checkPrivileges($path, '{DAV:}write-properties');
                 break;
@@ -924,7 +925,6 @@ class Plugin extends DAV\ServerPlugin {
                 // If MOVE is used beforeUnbind will also be used to check if
                 // the sourcenode can be deleted.
                 $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE);
-
                 break;
 
         }
@@ -1146,6 +1146,10 @@ class Plugin extends DAV\ServerPlugin {
                 $this->server->transactionType = 'report-expand-property';
                 $this->expandPropertyReport($report);
                 return false;
+            case '{DAV:}principal-match' :
+                $this->server->transactionType = 'report-principal-match';
+                $this->principalMatchReport($report);
+                return false;
 
         }
 
@@ -1241,7 +1245,24 @@ class Plugin extends DAV\ServerPlugin {
     /* Reports {{{ */
 
     /**
-     * The expand-property report is defined in RFC3253 section 3-8.
+     * The principal-match report is defined in RFC3744, section 9.3.
+     *
+     * This report allows a client to figure out based on the current user,
+     * or a principal URL, the principal URL and principal URLs of groups that
+     * principal belongs to.
+     *
+     * @param Xml\Request\PrincipalMatchReport $report
+     * @return void
+     */
+    protected function principalMatchReport($report) {
+
+        print_r($report);
+        die();
+
+    }
+
+    /**
+     * The expand-property report is defined in RFC3253 section 3.8.
      *
      * This report is very similar to a standard PROPFIND. The difference is
      * that it has the additional ability to look at properties containing a
diff --git a/lib/DAVACL/Xml/Request/PrincipalMatchReport.php b/lib/DAVACL/Xml/Request/PrincipalMatchReport.php
new file mode 100644
index 0000000..5c65077
--- /dev/null
+++ b/lib/DAVACL/Xml/Request/PrincipalMatchReport.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Sabre\DAVACL\Xml\Request;
+
+use Sabre\Xml\XmlDeserializable;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Deserializer;
+
+/**
+ * PrincipalMatchReport request parser.
+ *
+ * This class parses the {DAV:}principal-match REPORT, as defined
+ * in:
+ *
+ * https://tools.ietf.org/html/rfc3744#section-9.3
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class PrincipalMatchReport implements XmlDeserializable {
+
+    const SELF = 1;
+    const PRINCIPAL_PROPERTY = 2;
+
+    public $type;
+
+    public $properties = [];
+
+    public $principalProperty;
+
+    /**
+     * 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) {
+        
+        $reader->pushContext();
+        $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum';
+
+        $elems = Deserializer\keyValue(
+            $reader,
+            'DAV:'
+        );
+
+        $reader->popContext();
+
+        $principalMatch = new self();
+
+        $principalMatch->type = 'carrot';
+
+        if (array_key_exists('self', $elems)) {
+            $principalMatch->type = self::SELF;
+        }
+
+        if (array_key_exists('principal-property', $elems)) {
+            $principalMatch->type = self::PRINCIPAL_PROPERTY;
+            $principalMatch->principalProperty = $elems['principal-property'][0]['name'];
+        }
+
+        if (!empty($elems['prop'])) {
+            $principalMatch->properties = $elems['prop'];
+        }
+
+        return $principalMatch; 
+
+    }
+
+}
diff --git a/tests/Sabre/DAVACL/Xml/Request/PrincipalMatchReportTest.php b/tests/Sabre/DAVACL/Xml/Request/PrincipalMatchReportTest.php
new file mode 100644
index 0000000..1431ab3
--- /dev/null
+++ b/tests/Sabre/DAVACL/Xml/Request/PrincipalMatchReportTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Sabre\DAVACL\Xml\Request;
+
+class PrincipalMatchReportTest extends \Sabre\DAV\Xml\XmlTest {
+
+    protected $elementMap = [
+
+        '{DAV:}principal-match' => 'Sabre\DAVACL\Xml\Request\PrincipalMatchReport',
+
+    ];
+
+    function testDeserialize() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+   <D:principal-match xmlns:D="DAV:">
+     <D:principal-property>
+       <D:owner/>
+     </D:principal-property>
+   </D:principal-match>
+XML;
+
+        $result = $this->parse($xml);
+
+        $this->assertEquals(PrincipalMatchReport::PRINCIPAL_PROPERTY, $result['value']->type);
+        $this->assertEquals('{DAV:}owner', $result['value']->principalProperty);
+
+    }
+
+    function testDeserializeSelf() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+   <D:principal-match xmlns:D="DAV:">
+     <D:self />
+     <D:prop>
+        <D:foo />
+     </D:prop>
+   </D:principal-match>
+XML;
+
+        $result = $this->parse($xml);
+
+        $this->assertEquals(PrincipalMatchReport::SELF, $result['value']->type);
+        $this->assertNull($result['value']->principalProperty);
+        $this->assertEquals(['{DAV:}foo'], $result['value']->properties);
+
+    }
+
+}

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



More information about the Pkg-owncloud-commits mailing list