[Pkg-owncloud-commits] [php-sabredav] 01/220: {DAV:}share-resource parser.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:00 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit dcce5d5d9d0249aca244fef1e0b151b2adf9f2d2
Author: Evert Pot <me at evertpot.com>
Date: Tue Jul 7 13:55:08 2015 -0400
{DAV:}share-resource parser.
---
lib/DAV/Xml/Request/ShareResource.php | 139 ++++++++++++++++++++++
tests/Sabre/DAV/Xml/Request/ShareResourceTest.php | 68 +++++++++++
2 files changed, 207 insertions(+)
diff --git a/lib/DAV/Xml/Request/ShareResource.php b/lib/DAV/Xml/Request/ShareResource.php
new file mode 100644
index 0000000..28ff105
--- /dev/null
+++ b/lib/DAV/Xml/Request/ShareResource.php
@@ -0,0 +1,139 @@
+<?php
+
+namespace Sabre\DAV\Xml\Request;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+use Sabre\Xml\Element\KeyValue;
+use Sabre\DAV\Exception\BadRequest;
+
+/**
+ * ShareResource request parser.
+ *
+ * This class parses the {DAV:}share-resource POST request as defined in:
+ *
+ * https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-01#section-5.3.2.1
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class ShareResource implements XmlDeserializable {
+
+ /**
+ * The list of new people added or updated.
+ *
+ * Every element has the following keys:
+ * 1. href - An email address
+ * 2. comment - An optional description of the share
+ * 3. readOnly - true or false
+ *
+ * In addition to that, it might contain a list of webdav properties
+ * associated with the sharer. The most common one is {DAV:}displayname.
+ *
+ * @var array
+ */
+ public $set = [];
+
+ /**
+ * List of people removed from the share list.
+ *
+ * The list is a flat list of email addresses (including mailto:).
+ *
+ * @var array
+ */
+ public $remove = [];
+
+ /**
+ * Constructor
+ *
+ * @param array $set
+ * @param array $remove
+ */
+ function __construct(array $set, array $remove) {
+
+ $this->set = $set;
+ $this->remove = $remove;
+
+ }
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $elems = $reader->parseInnerTree([
+ '{DAV:}set-invitee' => 'Sabre\\Xml\\Element\\KeyValue',
+ '{DAV:}remove-invitee' => 'Sabre\\Xml\\Element\\KeyValue',
+ ]);
+
+ $set = [];
+ $remove = [];
+
+ foreach ($elems as $elem) {
+ switch ($elem['name']) {
+
+ case '{DAV:}set-invitee' :
+ $sharee = $elem['value'];
+
+ $setInvitee = [
+ 'href' => null,
+ 'comment' => null,
+ 'readOnly' => false,
+ ];
+ foreach($sharee as $key=>$value) {
+
+ switch($key) {
+
+ case '{DAV:}href' :
+ $setInvitee['href'] = $value;
+ break;
+ case '{DAV:}comment' :
+ $setInvitee['comment'] = $value;
+ break;
+ case '{DAV:}read' :
+ $setInvitee['readOnly'] = true;
+ break;
+ case '{DAV:}read-write' :
+ $setInvitee['readOnly'] = false;
+ break;
+ default :
+ $setInvitee[$key] = $value;
+ break;
+
+ }
+
+ }
+ $set[] = $setInvitee;
+ break;
+
+ case '{DAV:}remove-invitee' :
+ $remove[] = $elem['value']['{DAV:}href'];
+ break;
+
+ }
+ }
+
+ return new self($set, $remove);
+
+ }
+
+}
diff --git a/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
new file mode 100644
index 0000000..14a4b09
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Sabre\DAV\Xml\Request;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class ShareResourceTest extends XmlTest {
+
+ function testDeserialize() {
+
+ $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:share-resource xmlns:D="DAV:">
+ <D:set-invitee>
+ <D:href>mailto:eric at example.com</D:href>
+ <D:displayname>Eric York</D:displayname>
+ <D:comment>Shared workspace</D:comment>
+ <D:read-write />
+ </D:set-invitee>
+ <D:set-invitee>
+ <D:href>mailto:evert at example.com</D:href>
+ <D:displayname>Evert Pot</D:displayname>
+ <D:comment>Shared workspace</D:comment>
+ <D:read />
+ </D:set-invitee>
+ <D:remove-invitee>
+ <D:href>mailto:wilfredo at example.com</D:href>
+ </D:remove-invitee>
+</D:share-resource>
+XML;
+
+ $result = $this->parse($xml, [
+ '{DAV:}share-resource' => 'Sabre\\DAV\\Xml\\Request\\ShareResource'
+ ]);
+
+ $this->assertInstanceOf(
+ 'Sabre\\DAV\\Xml\\Request\\ShareResource',
+ $result['value']
+ );
+
+ $this->assertEquals(
+ [
+ [
+ 'href' => 'mailto:eric at example.com',
+ '{DAV:}displayname' => 'Eric York',
+ 'comment' => 'Shared workspace',
+ 'readOnly' => false,
+ ],
+ [
+ 'href' => 'mailto:evert at example.com',
+ '{DAV:}displayname' => 'Evert Pot',
+ 'comment' => 'Shared workspace',
+ 'readOnly' => true,
+ ],
+ ],
+ $result['value']->set
+ );
+
+ $this->assertEquals(
+ [
+ 'mailto:wilfredo at example.com',
+ ],
+ $result['value']->remove
+ );
+
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list