[Pkg-owncloud-commits] [php-sabredav] 106/163: Added support for supported-method-set.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:59 UTC 2014


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

taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.

commit 733749b538aaeef13554bb423f960979de6705e5
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sat May 3 02:09:08 2014 -0400

    Added support for supported-method-set.
---
 lib/Sabre/DAV/CorePlugin.php                       |  5 ++
 lib/Sabre/DAV/Property/SupportedMethodSet.php      | 68 ++++++++++++++++++++++
 lib/Sabre/DAV/Server.php                           | 12 ++--
 lib/Sabre/DAV/ServerPlugin.php                     | 10 ++--
 .../Sabre/DAV/Property/SupportedMethodSetTest.php  | 56 ++++++++++++++++++
 5 files changed, 142 insertions(+), 9 deletions(-)

diff --git a/lib/Sabre/DAV/CorePlugin.php b/lib/Sabre/DAV/CorePlugin.php
index 9594c82..1096a7f 100644
--- a/lib/Sabre/DAV/CorePlugin.php
+++ b/lib/Sabre/DAV/CorePlugin.php
@@ -814,6 +814,11 @@ class CorePlugin extends ServerPlugin {
         $propFind->handle('{DAV:}resourcetype', function() use ($node) {
             return new Property\ResourceType($this->server->getResourceTypeForNode($node));
         });
+        $propFind->handle('{DAV:}supported-method-set', function() use ($propFind) {
+            return new Property\SupportedMethodSet(
+                $this->server->getAllowedMethods($propFind->getPath())
+            );
+        });
 
     }
 
diff --git a/lib/Sabre/DAV/Property/SupportedMethodSet.php b/lib/Sabre/DAV/Property/SupportedMethodSet.php
new file mode 100644
index 0000000..2e21724
--- /dev/null
+++ b/lib/Sabre/DAV/Property/SupportedMethodSet.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Sabre\DAV\Property;
+
+use Sabre\DAV;
+
+/**
+ * supported-method-set property.
+ *
+ * This property is defined in RFC3253.
+ *
+ * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class SupportedMethodSet extends DAV\Property {
+
+    /**
+     * List of methods
+     *
+     * @var array
+     */
+    protected $methods = [];
+
+    /**
+     * Creates the property
+     *
+     * Any reports passed in the constructor should be valid HTTP methods.
+     *
+     * @param array $methods
+     */
+    public function __construct(array $method) {
+
+        $this->methods = $method;
+
+    }
+
+    /**
+     * Returns the list of supported methods.
+     *
+     * @return array
+     */
+    public function getValue() {
+
+        return $this->methods;
+
+    }
+
+    /**
+     * Serializes the node
+     *
+     * @param DAV\Server $server
+     * @param \DOMElement $prop
+     * @return void
+     */
+    public function serialize(DAV\Server $server, \DOMElement $prop) {
+
+        foreach($this->methods as $method) {
+
+            $supportedMethod = $prop->ownerDocument->createElement('d:supported-method');
+            $supportedMethod->setAttribute('name', $method);
+            $prop->appendChild($supportedMethod);
+
+        }
+
+    }
+
+}
diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index 306f2fe..28b1f70 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -125,6 +125,10 @@ class Server extends EventEmitter {
         '{DAV:}acl-restrictions',
         '{DAV:}inherited-acl-set',
 
+        // RFC3253
+        '{DAV:}supported-method-set',
+        '{DAV:}supported-report-set',
+
     ];
 
     /**
@@ -467,10 +471,10 @@ class Server extends EventEmitter {
     /**
      * Returns an array with all the supported HTTP methods for a specific uri.
      *
-     * @param string $uri
+     * @param string $path
      * @return array
      */
-    public function getAllowedMethods($uri) {
+    public function getAllowedMethods($path) {
 
         $methods = [
             'OPTIONS',
@@ -487,13 +491,13 @@ class Server extends EventEmitter {
 
         // The MKCOL is only allowed on an unmapped uri
         try {
-            $this->tree->getNodeForPath($uri);
+            $this->tree->getNodeForPath($path);
         } catch (Exception\NotFound $e) {
             $methods[] = 'MKCOL';
         }
 
         // We're also checking if any of the plugins register any new methods
-        foreach($this->plugins as $plugin) $methods = array_merge($methods, $plugin->getHTTPMethods($uri));
+        foreach($this->plugins as $plugin) $methods = array_merge($methods, $plugin->getHTTPMethods($path));
         array_unique($methods);
 
         return $methods;
diff --git a/lib/Sabre/DAV/ServerPlugin.php b/lib/Sabre/DAV/ServerPlugin.php
index c393f43..8fb43c2 100644
--- a/lib/Sabre/DAV/ServerPlugin.php
+++ b/lib/Sabre/DAV/ServerPlugin.php
@@ -36,7 +36,7 @@ abstract class ServerPlugin {
      */
     public function getFeatures() {
 
-        return array();
+        return [];
 
     }
 
@@ -47,12 +47,12 @@ abstract class ServerPlugin {
      * This method is passed a uri. It should only return HTTP methods that are
      * available for the specified uri.
      *
-     * @param string $uri
+     * @param string $path
      * @return array
      */
-    public function getHTTPMethods($uri) {
+    public function getHTTPMethods($path) {
 
-        return array();
+        return [];
 
     }
 
@@ -82,7 +82,7 @@ abstract class ServerPlugin {
      */
     public function getSupportedReportSet($uri) {
 
-        return array();
+        return [];
 
     }
 
diff --git a/tests/Sabre/DAV/Property/SupportedMethodSetTest.php b/tests/Sabre/DAV/Property/SupportedMethodSetTest.php
new file mode 100644
index 0000000..a1b93e4
--- /dev/null
+++ b/tests/Sabre/DAV/Property/SupportedMethodSetTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Sabre\DAV\Property;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+require_once 'Sabre/DAV/AbstractServer.php';
+
+class SupportedMethodSetTest extends DAV\AbstractServer {
+
+    public function sendPROPFIND($body) {
+
+        $request = new HTTP\Request('PROPFIND', '/', ['Depth' => '0' ]);
+        $request->setBody($body);
+
+        $this->server->httpRequest = $request;
+        $this->server->exec();
+
+    }
+
+    /**
+     */
+    function testMethods() {
+
+        $xml = '<?xml version="1.0"?>
+<d:propfind xmlns:d="DAV:">
+  <d:prop>
+    <d:supported-method-set />
+  </d:prop>
+</d:propfind>';
+
+        $this->sendPROPFIND($xml);
+
+        $this->assertEquals(207, $this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body);
+
+        $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body);
+        $xml = simplexml_load_string($body);
+        $xml->registerXPathNamespace('d','urn:DAV');
+
+        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
+        $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element');
+
+        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-method-set');
+        $this->assertEquals(1,count($data),'We expected 1 \'d:supported-method-set\' element');
+
+        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
+        $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element');
+
+        $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200');
+
+    }
+
+}
+

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