[Pkg-owncloud-commits] [php-sabredav] 121/163: Removed beforeGetProperties from Sync and CardDAV.

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 fb0d010182a6112fdc4a5854de4da3e04b2ec4cf
Author: Evert Pot <me at evertpot.com>
Date:   Wed May 7 16:48:47 2014 -0400

    Removed beforeGetProperties from Sync and CardDAV.
---
 lib/Sabre/CardDAV/Plugin.php  | 50 +++++++++++++++++--------------------------
 lib/Sabre/DAV/Sync/Plugin.php | 26 +++++++++-------------
 2 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/lib/Sabre/CardDAV/Plugin.php b/lib/Sabre/CardDAV/Plugin.php
index 1956db8..f587cac 100644
--- a/lib/Sabre/CardDAV/Plugin.php
+++ b/lib/Sabre/CardDAV/Plugin.php
@@ -51,8 +51,8 @@ class Plugin extends DAV\ServerPlugin {
     public function initialize(DAV\Server $server) {
 
         /* Events */
-        $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
-        $server->on('propFind',            [$this, 'propFind'],150);
+        $server->on('propFind',            [$this, 'propFindEarly']);
+        $server->on('propFind',            [$this, 'propFindLate'],150);
         $server->on('propPatch',           [$this, 'propPatch']);
         $server->on('report',              [$this, 'report']);
         $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
@@ -119,29 +119,23 @@ class Plugin extends DAV\ServerPlugin {
     /**
      * Adds all CardDAV-specific properties
      *
-     * @param string $path
+     * @param DAV\PropFind $propFind
      * @param DAV\INode $node
-     * @param array $requestedProperties
-     * @param array $returnedProperties
      * @return void
      */
-    public function beforeGetProperties($path, DAV\INode $node, array &$requestedProperties, array &$returnedProperties) {
+    public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) {
 
         if ($node instanceof DAVACL\IPrincipal) {
 
-            // calendar-home-set property
-            $addHome = '{' . self::NS_CARDDAV . '}addressbook-home-set';
-            if (in_array($addHome,$requestedProperties)) {
+            $path = $propFind->getPath();
 
-                unset($requestedProperties[array_search($addHome, $requestedProperties)]);
-                $returnedProperties[200][$addHome] = new DAV\Property\Href($this->getAddressBookHomeForPrincipal($path) . '/');
-            }
+            $propFind->handle('{' . self::NS_CARDDAV . '}addressbook-home-set', function() use ($path) {
+                return new DAV\Property\Href($this->getAddressBookHomeForPrincipal($path) . '/');
+            });
 
-            $directories = '{' . self::NS_CARDDAV . '}directory-gateway';
-            if ($this->directories && in_array($directories, $requestedProperties)) {
-                unset($requestedProperties[array_search($directories, $requestedProperties)]);
-                $returnedProperties[200][$directories] = new DAV\Property\HrefList($this->directories);
-            }
+            if ($this->directories) $propFind->handle('{' . self::NS_CARDDAV . '}directory-gateway', function() {
+                return new DAV\Property\HrefList($this->directories);
+            });
 
         }
 
@@ -150,35 +144,31 @@ class Plugin extends DAV\ServerPlugin {
             // The address-data property is not supposed to be a 'real'
             // property, but in large chunks of the spec it does act as such.
             // Therefore we simply expose it as a property.
-            $addressDataProp = '{' . self::NS_CARDDAV . '}address-data';
-            if (in_array($addressDataProp, $requestedProperties)) {
-                unset($requestedProperties[$addressDataProp]);
+            $propFind->handle('{' . self::NS_CARDDAV . '}address-data', function() use ($node) {
                 $val = $node->get();
                 if (is_resource($val))
                     $val = stream_get_contents($val);
 
-                $returnedProperties[200][$addressDataProp] = $val;
+                return $val;
+
+            });
 
-            }
         }
 
         if ($node instanceof UserAddressBooks) {
 
-            $meCardProp = '{http://calendarserver.org/ns/}me-card';
-            if (in_array($meCardProp, $requestedProperties)) {
+            $propFind->handle('{http://calendarserver.org/ns/}me-card', function() use ($node) {
 
-                $props = $this->server->getProperties($node->getOwner(), array('{http://sabredav.org/ns}vcard-url'));
+                $props = $this->server->getProperties($node->getOwner(), ['{http://sabredav.org/ns}vcard-url']);
                 if (isset($props['{http://sabredav.org/ns}vcard-url'])) {
 
-                    $returnedProperties[200][$meCardProp] = new DAV\Property\Href(
+                    return new DAV\Property\Href(
                         $props['{http://sabredav.org/ns}vcard-url']
                     );
-                    $pos = array_search($meCardProp, $requestedProperties);
-                    unset($requestedProperties[$pos]);
 
                 }
 
-            }
+            });
 
         }
 
@@ -651,7 +641,7 @@ class Plugin extends DAV\ServerPlugin {
      * This event is scheduled late in the process, after most work for
      * propfind has been done.
      */
-    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
+    public function propFindLate(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
diff --git a/lib/Sabre/DAV/Sync/Plugin.php b/lib/Sabre/DAV/Sync/Plugin.php
index 02ba5b9..4199846 100644
--- a/lib/Sabre/DAV/Sync/Plugin.php
+++ b/lib/Sabre/DAV/Sync/Plugin.php
@@ -66,8 +66,8 @@ class Plugin extends DAV\ServerPlugin {
 
         });
 
-        $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
-        $server->on('validateTokens',      [$this, 'validateTokens']);
+        $server->on('propFind',       [$this, 'propFind']);
+        $server->on('validateTokens', [$this, 'validateTokens']);
 
     }
 
@@ -282,24 +282,18 @@ class Plugin extends DAV\ServerPlugin {
      * This method is triggered whenever properties are requested for a node.
      * We intercept this to see if we can must return a {DAV:}sync-token.
      *
-     * @param string $path
+     * @param DAV\PropFind $propFind
      * @param DAV\INode $node
-     * @param array $requestedProperties
-     * @param array $returnedProperties
      * @return void
      */
-    public function beforeGetProperties($path, DAV\INode $node, array &$requestedProperties, array &$returnedProperties) {
+    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
 
-        if (!in_array('{DAV:}sync-token', $requestedProperties)) {
-            return;
-        }
-
-        if ($node instanceof ISyncCollection && $token = $node->getSyncToken()) {
-            // Unsetting the property from requested properties.
-            $index = array_search('{DAV:}sync-token', $requestedProperties);
-            unset($requestedProperties[$index]);
-            $returnedProperties[200]['{DAV:}sync-token'] = self::SYNCTOKEN_PREFIX . $token;
-        }
+        $propFind->handle('{DAV:}sync-token', function() use ($node) {
+            if (!$node instanceof ISyncCollection || !$token = $node->getSyncToken()) {
+                return;
+            }
+            return self::SYNCTOKEN_PREFIX . $token;
+        });
 
     }
 

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