[Pkg-owncloud-commits] [php-sabredav] 43/220: Sharee is now an XML element. Work on invite property.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:06 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 282c2613dd2d899fb2550a92610cead52bc156ee
Author: Evert Pot <me at evertpot.com>
Date: Mon Jan 11 20:55:44 2016 -0500
Sharee is now an XML element. Work on invite property.
---
lib/DAV/Sharing/Sharee.php | 64 ---------
lib/DAV/Xml/Element/Sharee.php | 166 ++++++++++++++++++++++
lib/DAV/Xml/Property/Invite.php | 72 ++++++++++
lib/DAV/Xml/Property/ShareAccess.php | 6 +-
lib/DAV/Xml/Request/ShareResource.php | 28 +---
tests/Sabre/DAV/Xml/Request/ShareResourceTest.php | 2 +-
6 files changed, 245 insertions(+), 93 deletions(-)
diff --git a/lib/DAV/Sharing/Sharee.php b/lib/DAV/Sharing/Sharee.php
deleted file mode 100644
index 3b4abf1..0000000
--- a/lib/DAV/Sharing/Sharee.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Sabre\DAV\Sharing;
-
-/**
- * This class acts as a value object for sharees. It's used to send around
- * information about sharees.
- *
- * @copyright Copyright (C) fruux GmbH. (https://fruux.com/)
- * @author Evert Pot (http://evertpot.com/)
- * @license http://sabre.io/license/ Modified BSD License
- */
-class Sharee {
-
- /**
- * A URL. Usually a mailto: address, could also be a principal url.
- * This uniquely identifies the sharee.
- *
- * @var string
- */
- public $href;
-
- /**
- * A list of WebDAV properties that describe the sharee. This might for
- * example contain a {DAV:}displayname with the real name of the user.
- *
- * @var array
- */
- public $properties = [];
-
- /**
- * Share access level. One of the Sabre\DAV\Sharing\Plugin::ACCESS
- * constants.
- *
- * Can be one of:
- *
- * ACCESS_READ
- * ACCESS_READWRITE
- * ACCESS_SHAREDOWNER
- * ACCESS_NOACCESS
- *
- * depending on context.
- *
- * @var int
- */
- public $shareAccess;
-
- /**
- * When a sharee is originally invited to a share, the sharer may add
- * a comment. This will be placed in this property.
- *
- * @var string
- */
- public $comment;
-
- /**
- * The status of the invite, should be one of the
- * Sabre\DAV\Sharing\Plugin::INVITE constants.
- *
- * @var int
- */
- public $invite;
-
-}
diff --git a/lib/DAV/Xml/Element/Sharee.php b/lib/DAV/Xml/Element/Sharee.php
new file mode 100644
index 0000000..d6b4fb3
--- /dev/null
+++ b/lib/DAV/Xml/Element/Sharee.php
@@ -0,0 +1,166 @@
+<?php
+
+namespace Sabre\DAV\Xml\Element;
+
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\DAV\Sharing\Plugin;
+use Sabre\Xml\Deserializer;
+use Sabre\Xml\Element;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+
+/**
+ * This class represents the {DAV:}sharee element.
+ *
+ * @copyright Copyright (C) fruux GmbH. (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class Sharee implements Element {
+
+ /**
+ * A URL. Usually a mailto: address, could also be a principal url.
+ * This uniquely identifies the sharee.
+ *
+ * @var string
+ */
+ public $href;
+
+ /**
+ * A list of WebDAV properties that describe the sharee. This might for
+ * example contain a {DAV:}displayname with the real name of the user.
+ *
+ * @var array
+ */
+ public $properties = [];
+
+ /**
+ * Share access level. One of the Sabre\DAV\Sharing\Plugin::ACCESS
+ * constants.
+ *
+ * Can be one of:
+ *
+ * ACCESS_READ
+ * ACCESS_READWRITE
+ * ACCESS_SHAREDOWNER
+ * ACCESS_NOACCESS
+ *
+ * depending on context.
+ *
+ * @var int
+ */
+ public $shareAccess;
+
+ /**
+ * When a sharee is originally invited to a share, the sharer may add
+ * a comment. This will be placed in this property.
+ *
+ * @var string
+ */
+ public $comment;
+
+ /**
+ * The status of the invite, should be one of the
+ * Sabre\DAV\Sharing\Plugin::INVITE constants.
+ *
+ * @var int
+ */
+ public $inviteStatus;
+
+ /**
+ * The xmlSerialize method is called during xml writing.
+ *
+ * Use the $writer argument to write its own xml serialization.
+ *
+ * An important note: do _not_ create a parent element. Any element
+ * implementing XmlSerializble should only ever write what's considered
+ * its 'inner xml'.
+ *
+ * The parent of the current element is responsible for writing a
+ * containing element.
+ *
+ * This allows serializers to be re-used for different element names.
+ *
+ * If you are opening new elements, you must also close them again.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ function xmlSerialize(Writer $writer) {
+
+ $writer->write([
+ '{DAV:}href' => $href,
+ '{DAV:}prop' => $this->properties,
+ '{DAV:}share-access' => new ShareAccess($this->shareAccess),
+ ]);
+ switch($this->inviteStatus) {
+ case Plugin::INVITE_NORESPONSE :
+ $write->writeElement('{DAV:}invite-noresponse');
+ break;
+ case Plugin::INVITE_ACCEPTED :
+ $write->writeElement('{DAV:}invite-accepted');
+ break;
+ case Plugin::INVITE_DECLINED :
+ $write->writeElement('{DAV:}invite-declined');
+ break;
+ case Plugin::INVITE_INVALID :
+ $write->writeElement('{DAV:}invite-invalid');
+ break;
+ }
+
+ }
+
+ /**
+ * 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) {
+
+ // Temporarily override configuration
+ $reader->pushContext();
+ $reader->elementMap['{DAV:}share-access'] = 'Sabre\DAV\Xml\Property\ShareAccess';
+ $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\keyValue';
+
+ $elems = Deserializer\keyValue($reader, 'DAV:');
+
+ // Restore previous configuration
+ $reader->popContext();
+
+ $sharee = new self();
+ if (!isset($elems['href'])) {
+ throw new BadRequest('Every {DAV:}sharee must have a {DAV:}href child-element');
+ }
+ $sharee->href = $elems['href'];
+
+ if (isset($elems['prop'])) {
+ $sharee->properties = $elems['prop'];
+ }
+ if (isset($elems['comment'])) {
+ $sharee->comment = $elems['comment'];
+ }
+ if (!isset($elems['share-access'])) {
+ throw new BadRequest('Every {DAV:}sharee must have a {DAV:}share-access child element');
+ }
+ $sharee->access = $elems['share-access']->getValue();
+ return $sharee;
+
+ }
+
+}
diff --git a/lib/DAV/Xml/Property/Invite.php b/lib/DAV/Xml/Property/Invite.php
new file mode 100644
index 0000000..0b61eac
--- /dev/null
+++ b/lib/DAV/Xml/Property/Invite.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Sabre\DAV\Xml\Property;
+
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\DAV\Sharing\Plugin as SharingPlugin;
+use Sabre\DAV\Sharing\Sharee;
+use Sabre\Xml\XmlSerializable;
+use Sabre\Xml\Writer;
+
+/**
+ * This class represents the {DAV:}invite property.
+ *
+ * This property is defined here:
+ * https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-03#section-4.4.2
+ *
+ * This property is used by clients to determine who currently has access to
+ * a shared resource, what their access level is and what their invite status
+ * is.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class Invite implements XmlSerializable {
+
+ /**
+ * A list of sharees
+ *
+ * @var Sharee[]
+ */
+ public $sharees = [];
+
+ /**
+ * Creates the property.
+ *
+ * @param Sharee[] $sharees
+ */
+ function __construct(array $sharees) {
+
+ $this->sharees = $sharees;
+
+ }
+
+ /**
+ * The xmlSerialize method is called during xml writing.
+ *
+ * Use the $writer argument to write its own xml serialization.
+ *
+ * An important note: do _not_ create a parent element. Any element
+ * implementing XmlSerializble should only ever write what's considered
+ * its 'inner xml'.
+ *
+ * The parent of the current element is responsible for writing a
+ * containing element.
+ *
+ * This allows serializers to be re-used for different element names.
+ *
+ * If you are opening new elements, you must also close them again.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ function xmlSerialize(Writer $writer) {
+
+ foreach($this->sharees as $sharee) {
+ $writer->writeElement('{DAV:}sharee', $sharee);
+ }
+
+ }
+
+}
diff --git a/lib/DAV/Xml/Property/ShareAccess.php b/lib/DAV/Xml/Property/ShareAccess.php
index b40626d..ab9bb37 100644
--- a/lib/DAV/Xml/Property/ShareAccess.php
+++ b/lib/DAV/Xml/Property/ShareAccess.php
@@ -12,14 +12,14 @@ use Sabre\Xml\Writer;
* This class represents the {DAV:}share-access property.
*
* This property is defined here:
- * TODO
+ * https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-03#section-4.4.1
*
* This property is used to indicate if a resource is a shared resource, and
* whether the instance of the shared resource is the original instance, or
* an instance belonging to a sharee.
*
- * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ShareAccess implements Element {
diff --git a/lib/DAV/Xml/Request/ShareResource.php b/lib/DAV/Xml/Request/ShareResource.php
index 316de7d..b230689 100644
--- a/lib/DAV/Xml/Request/ShareResource.php
+++ b/lib/DAV/Xml/Request/ShareResource.php
@@ -5,7 +5,7 @@ namespace Sabre\DAV\Xml\Request;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
use Sabre\Xml\Deserializer;
-use Sabre\DAV\Sharing\Sharee;
+use Sabre\DAV\Xml\Element\Sharee;
use Sabre\DAV\Exception\BadRequest;
/**
@@ -63,9 +63,7 @@ class ShareResource implements XmlDeserializable {
static function xmlDeserialize(Reader $reader) {
$elems = $reader->parseInnerTree([
- '{DAV:}sharee' => function(Reader $reader) {
- return Deserializer\keyValue($reader, 'DAV:');
- },
+ '{DAV:}sharee' => 'Sabre\DAV\Xml\Element\Sharee',
'{DAV:}share-access' => 'Sabre\DAV\Xml\Property\ShareAccess',
'{DAV:}prop' => 'Sabre\Xml\Deserializer\keyValue',
]);
@@ -74,27 +72,7 @@ class ShareResource implements XmlDeserializable {
foreach ($elems as $elem) {
if ($elem['name'] !== '{DAV:}sharee') continue;
-
- $xsharee = $elem['value'];
-
- $sharee = new Sharee();
- if (!isset($xsharee['href'])) {
- throw new BadRequest('Every {DAV:}sharee must have a {DAV:}href child-element');
- }
- $sharee->href = $xsharee['href'];
-
- if (isset($xsharee['prop'])) {
- $sharee->properties = $xsharee['prop'];
- }
- if (isset($xsharee['comment'])) {
- $sharee->comment = $xsharee['comment'];
- }
- if (!isset($xsharee['share-access'])) {
- throw new BadRequest('Every {DAV:}sharee must have a {DAV:}share-access child element');
- }
- $sharee->access = $xsharee['share-access']->getValue();
-
- $sharees[] = $sharee;
+ $sharees[] = $elem['value'];
}
diff --git a/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
index 7f97c3f..250c1e1 100644
--- a/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
+++ b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
@@ -3,7 +3,7 @@
namespace Sabre\DAV\Xml\Request;
use Sabre\DAV\Xml\XmlTest;
-use Sabre\DAV\Sharing\Sharee;
+use Sabre\DAV\Xml\Element\Sharee;
use Sabre\DAV\Sharing\Plugin;
class ShareResourceTest extends XmlTest {
--
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