[Pkg-owncloud-commits] [php-sabredav] 63/275: Using the new property API.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:55:52 UTC 2014


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

taffit pushed a commit to branch master
in repository php-sabredav.

commit 5dfdf055c294853f760d8513a07ffa9028c9293c
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Tue Jun 10 17:04:25 2014 -0400

    Using the new property API.
---
 lib/CalDAV/Schedule/Plugin.php | 76 +++++++++++++++++-------------------------
 1 file changed, 30 insertions(+), 46 deletions(-)

diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index e4b0ffe..86c3e49 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -7,6 +7,8 @@ use
     Sabre\DAV\ServerPlugin,
     Sabre\DAV\Property\Href,
     Sabre\DAV\Property\HrefList,
+    Sabre\DAV\PropFind,
+    Sabre\DAV\INode,
     Sabre\HTTP\RequestInterface,
     Sabre\HTTP\ResponseInterface,
     Sabre\VObject,
@@ -187,7 +189,7 @@ class Plugin extends ServerPlugin {
 
         $this->server = $server;
         $server->on('method:POST', [$this,'httpPost']);
-        $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
+        $server->on('propFind',            [$this, 'propFind']);
         $server->on('beforeCreateFile',    [$this, 'beforeCreateFile']);
         $server->on('schedule',            [$this, 'scheduleLocalDelivery']);
 
@@ -271,65 +273,47 @@ class Plugin extends ServerPlugin {
 
     }
 
-
     /**
-     * beforeGetProperties
+     * This method handler is invoked during fetching of properties.
      *
-     * This method handler is invoked before any after properties for a
-     * resource are fetched. This allows us to add in any CalDAV specific
-     * properties.
+     * We use this event to add calendar-auto-schedule-specific properties.
      *
-     * @param string $path
-     * @param \Sabre\DAV\INode $node
-     * @param array $requestedProperties
-     * @param array $returnedProperties
+     * @param PropFind $propFind
+     * @param INode $node
      * @return void
      */
-    public function beforeGetProperties($path, \Sabre\DAV\INode $node, &$requestedProperties, &$returnedProperties) {
-
-        $caldavPlugin = $this->server->getPlugin('caldav');
-
-        if ($node instanceof DAVACL\IPrincipal) {
-
-            $principalUrl = $node->getPrincipalUrl();
-
-            // schedule-outbox-URL property
-            $scheduleProp = '{' . self::NS_CALDAV . '}schedule-outbox-URL';
-            if (in_array($scheduleProp,$requestedProperties)) {
-
-                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
-                $outboxPath = $calendarHomePath . '/outbox';
+    public function propFind(PropFind $propFind, INode $node) {
 
-                unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
-                $returnedProperties[200][$scheduleProp] = new Href($outboxPath);
+        if (!$node instanceof DAVACL\IPrincipal) return;
 
-            }
-
-            // schedule-inbox-URL property
-            $scheduleProp = '{' . self::NS_CALDAV . '}schedule-inbox-URL';
-            if (in_array($scheduleProp,$requestedProperties)) {
-
-                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
-                $inboxPath = $calendarHomePath . '/inbox';
+        $caldavPlugin = $this->server->getPlugin('caldav');
+        $principalUrl = $node->getPrincipalUrl();
 
-                unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
-                $returnedProperties[200][$scheduleProp] = new Href($inboxPath);
+        // schedule-outbox-URL property
+        $propFind->handle('{' . self::NS_CALDAV . '}schedule-outbox-URL' , function() use ($principalUrl, $caldavPlugin) {
 
-            }
+            $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+            $outboxPath = $calendarHomePath . '/outbox';
 
+            return new Href($outboxPath);
 
-            // calendar-user-address-set property
-            $calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
-            if (in_array($calProp,$requestedProperties)) {
+        });
+        // schedule-inbox-URL property
+        $propFind->handle('{' . self::NS_CALDAV . '}schedule-inbox-URL' , function() use ($principalUrl, $caldavPlugin) {
 
-                $addresses = $node->getAlternateUriSet();
-                $addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl() . '/';
-                unset($requestedProperties[array_search($calProp, $requestedProperties)]);
-                $returnedProperties[200][$calProp] = new HrefList($addresses, false);
+            $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+            $inboxPath = $calendarHomePath . '/inbox';
 
-            }
+            return new Href($inboxPath);
 
-        } // instanceof IPrincipal
+        });
+        // The calendar-user-address-set property is basically mapped to
+        // the {DAV:}alternate-URI-set property.
+        $propFind->handle('{' . self::NS_CALDAV . '}calendar-user-address-set', function() use ($node) {
+            $addresses = $node->getAlternateUriSet();
+            $addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl() . '/';
+            return new HrefList($addresses, 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