[Pkg-owncloud-commits] [php-sabredav] 02/148: Migrated PROPFIND to the new xml system.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:36:58 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 ac810b24db294f9cd650dab6f7d160cbd5269569
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Fri Nov 14 20:18:35 2014 -0500

    Migrated PROPFIND to the new xml system.
---
 lib/DAV/CorePlugin.php                    | 17 +++++++++++------
 lib/DAV/Server.php                        | 23 -----------------------
 lib/DAV/TemporaryFileFilterPlugin.php     |  2 --
 lib/DAV/XMLUtil.php                       |  1 +
 tests/Sabre/DAV/HTTPPreferParsingTest.php |  2 ++
 5 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/lib/DAV/CorePlugin.php b/lib/DAV/CorePlugin.php
index a1c2df4..863f029 100644
--- a/lib/DAV/CorePlugin.php
+++ b/lib/DAV/CorePlugin.php
@@ -49,8 +49,9 @@ class CorePlugin extends ServerPlugin {
         $server->on('propFind',         [$this, 'propFindNode'], 120);
         $server->on('propFind',         [$this, 'propFindLate'], 200);
 
-        $server->xml->elementMap += [
-            '{DAV:}propfind' => 'Sabre\\XML\\Request\\PropFind',
+        $server->xml->elementMap = [
+            '{DAV:}propfind' => 'Sabre\\DAV\\XML\\Request\\PropFind',
+            '{DAV:}prop'     => 'Sabre\\XML\\Element\\Elements',
         ];
 
     }
@@ -323,17 +324,21 @@ class CorePlugin extends ServerPlugin {
         $requestBody = $request->getBodyAsString();
         if (strlen($requestBody)) {
             $propFindXml = $this->server->xml->parse($requestBody);
-            print_r($propFindXml);
-            $properties = $propFindXml['{DAV:}prop'];
+            if ($propFindXml['name'] !== '{DAV:}propfind') {
+                throw new Exception\UnsupportedMediaType('The root element of this request must be {DAV:}propfind');
+            }
+            $propFindXml = $propFindXml['value'];
         } else {
-            $properties = [];
+            $propFindXml = new XML\Request\PropFind();
+            $propFindXml->allProp = true;
+            $propFindXml->properties = [];
         }
 
         $depth = $this->server->getHTTPDepth(1);
         // The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled
         if (!$this->server->enablePropfindDepthInfinity && $depth != 0) $depth = 1;
 
-        $newProperties = $this->server->getPropertiesForPath($path, $properties, $depth);
+        $newProperties = $this->server->getPropertiesForPath($path, $propFindXml->properties, $depth);
 
         // This is a multi-status response
         $response->setStatus(207);
diff --git a/lib/DAV/Server.php b/lib/DAV/Server.php
index fd78de1..dccee88 100644
--- a/lib/DAV/Server.php
+++ b/lib/DAV/Server.php
@@ -1719,29 +1719,6 @@ class Server extends EventEmitter {
         return $newProperties;
 
     }
-
-    /**
-     * This method parses the PROPFIND request and returns its information
-     *
-     * This will either be a list of properties, or an empty array; in which case
-     * an {DAV:}allprop was requested.
-     *
-     * @param string $body
-     * @return array
-     */
-    function parsePropFindRequest($body) {
-
-        // If the propfind body was empty, it means IE is requesting 'all' properties
-        if (!$body) return [];
-
-        $dom = XMLUtil::loadDOMDocument($body);
-        $elem = $dom->getElementsByTagNameNS('urn:DAV','propfind')->item(0);
-        if (is_null($elem)) throw new Exception\UnsupportedMediaType('We could not find a {DAV:}propfind element in the xml request body');
-
-        return array_keys(XMLUtil::parseProperties($elem));
-
-    }
-
     // }}}
 
 }
diff --git a/lib/DAV/TemporaryFileFilterPlugin.php b/lib/DAV/TemporaryFileFilterPlugin.php
index 1af54d9..b296c26 100644
--- a/lib/DAV/TemporaryFileFilterPlugin.php
+++ b/lib/DAV/TemporaryFileFilterPlugin.php
@@ -264,8 +264,6 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
         $hR->setStatus(207);
         $hR->setHeader('Content-Type','application/xml; charset=utf-8');
 
-        $this->server->parsePropFindRequest($request->getBodyAsString());
-
         $properties = [
             'href' => $request->getPath(),
             200 => [
diff --git a/lib/DAV/XMLUtil.php b/lib/DAV/XMLUtil.php
index 3ecab3b..af63b9b 100644
--- a/lib/DAV/XMLUtil.php
+++ b/lib/DAV/XMLUtil.php
@@ -31,6 +31,7 @@ class XMLUtil {
     function parse($input) {
 
         $reader = new XML\Reader();
+        $reader->elementMap = $this->elementMap;
         if ($input instanceof \Sabre\HTTP\MessageInterface) {
             $reader->xml($input->getBodyAsString());
         } else {
diff --git a/tests/Sabre/DAV/HTTPPreferParsingTest.php b/tests/Sabre/DAV/HTTPPreferParsingTest.php
index 9eaed82..765a59a 100644
--- a/tests/Sabre/DAV/HTTPPreferParsingTest.php
+++ b/tests/Sabre/DAV/HTTPPreferParsingTest.php
@@ -131,6 +131,8 @@ BLA
 
         $response = $this->request($request);
 
+        $this->assertEquals(207, $response->getStatus(), $response->getBodyAsString());
+
         $this->assertTrue(strpos($response->body, 'resourcetype')!==false);
         $this->assertTrue(strpos($response->body, 'something')===false);
 

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