[Pkg-owncloud-commits] [php-sabredav] 118/163: Eliminated afterGetProperties

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:55:00 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 c6a00f5ee4c2b83c0858cabc2c01cc33c0133c56
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Mon May 5 18:03:21 2014 -0400

    Eliminated afterGetProperties
---
 ChangeLog.md                                       |  1 +
 lib/Sabre/CardDAV/Plugin.php                       | 19 ++++-----
 lib/Sabre/DAV/Locks/Plugin.php                     | 49 ++++++++--------------
 lib/Sabre/DAV/Server.php                           | 17 --------
 .../Sabre/DAV/Property/SupportedReportSetTest.php  | 22 +++-------
 tests/Sabre/DAVACL/AllowAccessTest.php             | 37 ----------------
 6 files changed, 34 insertions(+), 111 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 7a8570f..a597939 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -8,6 +8,7 @@ ChangeLog
   document for more information. This allows for creation of a generic property
   storage, and other property-related functionality that was not possible
   before.
+* BC Break: Removed 'propertyUpdate' and 'afterGetProperties' events.
 * Added: Support for the `{DAV:}supported-method-set` property server-wide.
 * Making it easier for implementors to override how the CardDAV addressbook
   home is located.
diff --git a/lib/Sabre/CardDAV/Plugin.php b/lib/Sabre/CardDAV/Plugin.php
index 69b9b65..1956db8 100644
--- a/lib/Sabre/CardDAV/Plugin.php
+++ b/lib/Sabre/CardDAV/Plugin.php
@@ -52,7 +52,7 @@ class Plugin extends DAV\ServerPlugin {
 
         /* Events */
         $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
-        $server->on('afterGetProperties',  [$this, 'afterGetProperties']);
+        $server->on('propFind',            [$this, 'propFind'],150);
         $server->on('propPatch',           [$this, 'propPatch']);
         $server->on('report',              [$this, 'report']);
         $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
@@ -646,26 +646,25 @@ class Plugin extends DAV\ServerPlugin {
     }
 
     /**
-     * This event is triggered after webdav-properties have been retrieved.
+     * This event is triggered when fetching properties.
      *
-     * @return bool
+     * This event is scheduled late in the process, after most work for
+     * propfind has been done.
      */
-    public function afterGetProperties($uri, &$properties, DAV\INode $node) {
+    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
 
         // If the request was made using the SOGO connector, we must rewrite
         // the content-type property. By default SabreDAV will send back
         // text/x-vcard; charset=utf-8, but for SOGO we must strip that last
         // part.
-        if (!isset($properties[200]['{DAV:}getcontenttype']))
-            return;
-
         if (strpos($this->server->httpRequest->getHeader('User-Agent'),'Thunderbird')===false) {
             return;
         }
-
-        if (strpos($properties[200]['{DAV:}getcontenttype'],'text/x-vcard')===0) {
-            $properties[200]['{DAV:}getcontenttype'] = 'text/x-vcard';
+        $contentType = $propFind->get('{DAV:}getcontenttype');
+        if (!$contentType || strpos($contentType, 'text/x-vcard')!==0) {
+           return;
         }
+        $propFind->set('{DAV:}getcontenttype', 'text/x-vcard');
 
     }
 
diff --git a/lib/Sabre/DAV/Locks/Plugin.php b/lib/Sabre/DAV/Locks/Plugin.php
index bb178cb..7ff5d4b 100644
--- a/lib/Sabre/DAV/Locks/Plugin.php
+++ b/lib/Sabre/DAV/Locks/Plugin.php
@@ -59,10 +59,10 @@ class Plugin extends DAV\ServerPlugin {
     public function initialize(DAV\Server $server) {
 
         $this->server = $server;
-        $server->on('method:LOCK',        [$this, 'httpLock']);
-        $server->on('method:UNLOCK',      [$this, 'httpUnlock']);
-        $server->on('afterGetProperties', [$this, 'afterGetProperties']);
-        $server->on('validateTokens',     [$this, 'validateTokens']);
+        $server->on('method:LOCK',    [$this, 'httpLock']);
+        $server->on('method:UNLOCK',  [$this, 'httpUnlock']);
+        $server->on('validateTokens', [$this, 'validateTokens']);
+        $server->on('propFind',       [$this, 'propFind']);
 
     }
 
@@ -84,33 +84,20 @@ class Plugin extends DAV\ServerPlugin {
      * This method is called after most properties have been found
      * it allows us to add in any Lock-related properties
      *
-     * @param string $path
-     * @param array $newProperties
-     * @return bool
+     * @param DAV\PropFind $propFind
+     * @param DAV\INode $node
+     * @return void
      */
-    public function afterGetProperties($path, &$newProperties) {
-
-        foreach($newProperties[404] as $propName=>$discard) {
-
-            switch($propName) {
-
-                case '{DAV:}supportedlock' :
-                    $val = false;
-                    if ($this->locksBackend) $val = true;
-                    $newProperties[200][$propName] = new DAV\Property\SupportedLock($val);
-                    unset($newProperties[404][$propName]);
-                    break;
+    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
 
-                case '{DAV:}lockdiscovery' :
-                    $newProperties[200][$propName] = new DAV\Property\LockDiscovery($this->getLocks($path));
-                    unset($newProperties[404][$propName]);
-                    break;
-
-            }
-
-
-        }
-        return true;
+        $propFind->handle('{DAV:}supportedlock', function() {
+            return new DAV\Property\SupportedLock(!!$this->locksBackend);
+        });
+        $propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) {
+            return new DAV\Property\LockDiscovery(
+                $this->getLocks( $propFind->getPath() )
+            );
+        });
 
     }
 
@@ -127,9 +114,9 @@ class Plugin extends DAV\ServerPlugin {
     public function getHTTPMethods($uri) {
 
         if ($this->locksBackend)
-            return array('LOCK','UNLOCK');
+            return ['LOCK','UNLOCK'];
 
-        return array();
+        return [];
 
     }
 
diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index 329190c..22b8bfd 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -1045,23 +1045,6 @@ class Server extends EventEmitter {
 
         }
 
-        // Note: this event is also deprecated, and will be removed in a future
-        // version.
-        $newProperties = $propFind->getResultForMultiStatus();
-
-        $this->emit('afterGetProperties',[$propFind->getPath(), &$newProperties, $node]);
-
-        // Ew
-        foreach($newProperties as $status=>$propertyList) {
-
-            foreach($propertyList as $propertyName=>$value) {
-
-                $propFind->set($propertyName, $value, $status);
-
-            }
-
-        }
-
         return true;
 
     }
diff --git a/tests/Sabre/DAV/Property/SupportedReportSetTest.php b/tests/Sabre/DAV/Property/SupportedReportSetTest.php
index f1d3390..1866d5c 100644
--- a/tests/Sabre/DAV/Property/SupportedReportSetTest.php
+++ b/tests/Sabre/DAV/Property/SupportedReportSetTest.php
@@ -64,7 +64,12 @@ class SupportedReportSetTest extends DAV\AbstractServer {
     function testCustomReport() {
 
         // Intercepting the report property
-        $this->server->on('afterGetProperties', [$this,'addProp']);
+        $this->server->on('propFind', function(DAV\PropFind $propFind, DAV\INode $node) {
+            if ($prop = $propFind->get('{DAV:}supported-report-set')) {
+                $prop->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport');
+                $prop->addReport('{DAV:}anotherreport');
+            }
+        },200);
 
         $xml = '<?xml version="1.0"?>
 <d:propfind xmlns:d="DAV:">
@@ -107,20 +112,5 @@ class SupportedReportSetTest extends DAV\AbstractServer {
 
     }
 
-    /**
-     * This method is used as a callback for afterGetProperties
-     */
-    function addProp($path, &$properties) {
-
-        if (isset($properties[200]['{DAV:}supported-report-set'])) {
-            $properties[200]['{DAV:}supported-report-set']->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport');
-            $properties[200]['{DAV:}supported-report-set']->addReport('{DAV:}anotherreport');
-        }
-
-    }
-
-
-
 }
 
-?>
diff --git a/tests/Sabre/DAVACL/AllowAccessTest.php b/tests/Sabre/DAVACL/AllowAccessTest.php
index 3034d3d..14a8000 100644
--- a/tests/Sabre/DAVACL/AllowAccessTest.php
+++ b/tests/Sabre/DAVACL/AllowAccessTest.php
@@ -128,41 +128,4 @@ class AllowAccessTest extends \PHPUnit_Framework_TestCase {
 
     }
 
-    function testAfterGetProperties() {
-
-        $properties = array(
-            'href' => 'foo',
-            '200' => array(
-                '{DAV:}displayname' => 'foo',
-                '{DAV:}getcontentlength' => 500,
-            ),
-            '404' => array(
-                '{DAV:}bar' => null,
-            ),
-            '403' => array(
-                '{DAV:}owner' => null,
-            ),
-        );
-
-        $expected = array(
-            'href' => 'foo',
-            '200' => array(
-                '{DAV:}displayname' => 'foo',
-                '{DAV:}getcontentlength' => 500,
-            ),
-            '404' => array(
-                '{DAV:}bar' => null,
-            ),
-            '403' => array(
-                '{DAV:}owner' => null,
-            ),
-        );
-
-        $r = $this->server->emit('afterGetProperties', ['testdir',&$properties]);
-        $this->assertTrue($r);
-
-        $this->assertEquals($expected, $properties);
-
-    }
-
 }

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