[Pkg-owncloud-commits] [php-sabredav] 46/148: New DAVACL reports.

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 0146b963e7ae9848c20f0eba106566c40cd6fda5
Author: Evert Pot <me at evertpot.com>
Date:   Tue Feb 17 23:29:20 2015 -0500

    New DAVACL reports.
---
 lib/DAVACL/Plugin.php                              | 126 ++++-----------------
 lib/DAVACL/Xml/Request/ExpandPropertyReport.php    |   6 +-
 .../Xml/Request/PrincipalPropertySearchReport.php  |   6 +-
 .../Request/PrincipalSearchPropertySetReport.php   |  46 ++------
 4 files changed, 37 insertions(+), 147 deletions(-)

diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 4cf137c..e761675 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -712,6 +712,7 @@ class Plugin extends DAV\ServerPlugin {
         $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
         $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';
 
     }
 
@@ -1188,57 +1189,46 @@ class Plugin extends DAV\ServerPlugin {
      * of properties the client may search on, using the
      * {DAV:}principal-property-search report.
      *
-     * @param \DOMDocument $dom
+     * @param Xml\Request\PrincipalSearchPropertySetReport $report
      * @return void
      */
-    protected function principalSearchPropertySetReport(\DOMDocument $dom) {
+    protected function principalSearchPropertySetReport($report) {
 
         $httpDepth = $this->server->getHTTPDepth(0);
         if ($httpDepth!==0) {
             throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
         }
 
-        if ($dom->firstChild->hasChildNodes())
-            throw new DAV\Exception\BadRequest('The principal-search-property-set report element is not allowed to have child elements');
-
-        $dom = new \DOMDocument('1.0','utf-8');
-        $dom->formatOutput = true;
-        $root = $dom->createElement('d:principal-search-property-set');
-        $dom->appendChild($root);
-        // Adding in default namespaces
-        foreach($this->server->xmlNamespaces as $namespace=>$prefix) {
-
-            $root->setAttribute('xmlns:' . $prefix,$namespace);
-
-        }
-
-        $nsList = $this->server->xmlNamespaces;
+        $writer = $this->server->xml->getWriter();
+        $writer->startElement('{DAV:}principal-search-property-set');
 
         foreach($this->principalSearchPropertySet as $propertyName=>$description) {
 
-            $psp = $dom->createElement('d:principal-search-property');
-            $root->appendChild($psp);
+            $writer->startElement('{DAV:}principal-search-property');
+            $writer->startElement('{DAV:}prop');
 
-            $prop = $dom->createElement('d:prop');
-            $psp->appendChild($prop);
+            $writer->writeElement($propertyName);
 
-            $propName = null;
-            preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
+            $writer->endElement(); // prop
 
-            $currentProperty = $dom->createElement($nsList[$propName[1]] . ':' . $propName[2]);
-            $prop->appendChild($currentProperty);
+            if ($description) {
+                $writer->write([[
+                    'name' => '{DAV:}description',
+                    'value' => $description,
+                    'attributes' => ['xml:lang' => 'en']
+                ]]);
+            }
 
-            $descriptionElem = $dom->createElement('d:description');
-            $descriptionElem->setAttribute('xml:lang','en');
-            $descriptionElem->appendChild($dom->createTextNode($description));
-            $psp->appendChild($descriptionElem);
+            $writer->endElement(); // principal-search-property
 
 
         }
 
+        $writer->endElement(); // principal-search-property-set
+
         $this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
         $this->server->httpResponse->setStatus(200);
-        $this->server->httpResponse->setBody($dom->saveXML());
+        $this->server->httpResponse->setBody($writer->outputMemory());
 
     }
 
@@ -1278,84 +1268,8 @@ class Plugin extends DAV\ServerPlugin {
 
     }
 
-    /**
-     * parsePrincipalPropertySearchReportRequest
-     *
-     * This method parses the request body from a
-     * {DAV:}principal-property-search report.
-     *
-     * This method returns an array with two elements:
-     *  1. an array with properties to search on, and their values
-     *  2. a list of propertyvalues that should be returned for the request.
-     *
-     * @param \DOMDocument $dom
-     * @return array
-     */
-    protected function parsePrincipalPropertySearchReportRequest($dom) {
-
-        $httpDepth = $this->server->getHTTPDepth(0);
-        if ($httpDepth!==0) {
-            throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
-        }
-
-        $searchProperties = [];
-
-        $applyToPrincipalCollectionSet = false;
-
-        $test = $dom->firstChild->getAttribute('test') === 'anyof' ? 'anyof' : 'allof';
-
-        // Parsing the search request
-        foreach($dom->firstChild->childNodes as $searchNode) {
-
-            if (DAV\XMLUtil::toClarkNotation($searchNode) == '{DAV:}apply-to-principal-collection-set') {
-                $applyToPrincipalCollectionSet = true;
-            }
-
-            if (DAV\XMLUtil::toClarkNotation($searchNode)!=='{DAV:}property-search')
-                continue;
-
-            $propertyName = null;
-            $propertyValue = null;
-
-            foreach($searchNode->childNodes as $childNode) {
-
-                switch(DAV\XMLUtil::toClarkNotation($childNode)) {
-
-                    case '{DAV:}prop' :
-                        $property = DAV\XMLUtil::parseProperties($searchNode);
-                        reset($property);
-                        $propertyName = key($property);
-                        break;
-
-                    case '{DAV:}match' :
-                        $propertyValue = $childNode->textContent;
-                        break;
-
-                }
-
-
-            }
-
-            if (is_null($propertyName) || is_null($propertyValue))
-                throw new DAV\Exception\BadRequest('Invalid search request. propertyname: ' . $propertyName . '. propertvvalue: ' . $propertyValue);
-
-            $searchProperties[$propertyName] = $propertyValue;
-
-        }
-
-        return [
-            $searchProperties,
-            array_keys(DAV\XMLUtil::parseProperties($dom->firstChild)),
-            $applyToPrincipalCollectionSet,
-            $test
-        ];
-
-    }
-
-
     /* }}} */
 
-
     /**
      * Returns a bunch of meta-data about the plugin.
      *
diff --git a/lib/DAVACL/Xml/Request/ExpandPropertyReport.php b/lib/DAVACL/Xml/Request/ExpandPropertyReport.php
index 0702d26..36dab18 100644
--- a/lib/DAVACL/Xml/Request/ExpandPropertyReport.php
+++ b/lib/DAVACL/Xml/Request/ExpandPropertyReport.php
@@ -12,9 +12,9 @@ use Sabre\Xml\XmlDeserializable;
  *
  * http://tools.ietf.org/html/rfc3253#section-3.8
  *
- * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
- * @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 ExpandPropertyReport implements XmlDeserializable {
 
diff --git a/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php b/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
index d28f78e..14701b0 100644
--- a/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
+++ b/lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
@@ -14,9 +14,9 @@ use Sabre\DAV\Exception\BadRequest;
  *
  * https://tools.ietf.org/html/rfc3744#section-9.4
  *
- * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
- * @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 PrincipalPropertySearchReport implements XmlDeserializable {
 
diff --git a/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php b/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
index 3a5d234..0d7b3e8 100644
--- a/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
+++ b/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
@@ -1,13 +1,10 @@
 <?php
 
-namespace Sabre\DAVACL\XML\Request;
+namespace Sabre\DAVACL\Xml\Request;
 
-use
-    Sabre\XML\Element,
-    Sabre\XML\Reader,
-    Sabre\XML\Writer,
-    Sabre\DAV\Exception\CannotSerialize,
-    Sabre\DAV\Exception\BadRequest;
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+use Sabre\DAV\Exception\BadRequest;
 
 /**
  * PrincipalSearchPropertySetReport request parser.
@@ -17,32 +14,11 @@ use
  *
  * https://tools.ietf.org/html/rfc3744#section-9.5
  *
- * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
- * @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 PrincipalSearchPropertySetReport implements Element {
-
-    /**
-     * The serialize method is called during xml writing.
-     *
-     * It should use the $writer argument to encode this object into XML.
-     *
-     * Important note: it is not needed to create the parent element. The
-     * parent element is already created, and we only have to worry about
-     * attributes, child elements and text (if any).
-     *
-     * Important note 2: If you are writing any new elements, you are also
-     * responsible for closing them.
-     *
-     * @param Writer $writer
-     * @return void
-     */
-    public function serializeXml(Writer $writer) {
-
-        throw new CannotSerialize('This element cannot be serialized.');
-
-    }
+class PrincipalSearchPropertySetReport implements XmlDeserializable {
 
     /**
      * The deserialize method is called during xml parsing.
@@ -53,8 +29,8 @@ class PrincipalSearchPropertySetReport implements Element {
      * Often you want to return an instance of the current class, but you are
      * free to return other data as well.
      *
-     * Important note 2: You are responsible for advancing the reader to the
-     * next element. Not doing anything will result in a never-ending loop.
+     * 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();
@@ -65,7 +41,7 @@ class PrincipalSearchPropertySetReport implements Element {
      * @param Reader $reader
      * @return mixed
      */
-    static public function deserializeXml(Reader $reader) {
+    static function xmlDeserialize(Reader $reader) {
 
         if (!$reader->isEmptyElement) {
             throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');

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