[Pkg-owncloud-commits] [php-sabredav] 31/148: Transplanted Xml stuff from xml-rewrite branch
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:07 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 3a812de456e50dcb137f8a2b6a1b6b41ece27259
Author: Evert Pot <me at evertpot.com>
Date: Sun Feb 8 18:29:27 2015 -0500
Transplanted Xml stuff from xml-rewrite branch
---
lib/CardDAV/Xml/Filter/ParamFilter.php | 118 ++++++++++++++
lib/CardDAV/Xml/Filter/PropFilter.php | 123 +++++++++++++++
lib/CardDAV/Xml/Property/SupportedAddressData.php | 108 +++++++++++++
.../Xml/Request/AddressBookMultiGetReport.php | 114 ++++++++++++++
lib/CardDAV/Xml/Request/AddressBookQueryReport.php | 171 +++++++++++++++++++++
5 files changed, 634 insertions(+)
diff --git a/lib/CardDAV/Xml/Filter/ParamFilter.php b/lib/CardDAV/Xml/Filter/ParamFilter.php
new file mode 100644
index 0000000..91ccc66
--- /dev/null
+++ b/lib/CardDAV/Xml/Filter/ParamFilter.php
@@ -0,0 +1,118 @@
+<?php
+
+namespace Sabre\CardDAV\XML\Filter;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotSerialize,
+ Sabre\DAV\Exception\BadRequest,
+ Sabre\CardDAV\Plugin;
+
+
+/**
+ * ParamFilter parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}param-filter XML
+ * element, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-10.5.2
+ *
+ * The result will be spit out as an array.
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class ParamFilter implements Element {
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ throw new CannotSerialize('This element cannot be serialized.');
+
+ }
+
+ /**
+ * 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.
+ *
+ * Important note 2: 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 public function deserializeXml(Reader $reader) {
+
+ $result = [
+ 'name' => null,
+ 'is-not-defined' => false,
+ 'text-match' => null,
+ ];
+
+ $att = $reader->parseAttributes();
+ $result['name'] = $att['name'];
+
+ if (isset($att['test']) && $att['test']==='allof') {
+ $result['test'] = 'allof';
+ }
+
+ $elems = $reader->parseInnerTree();
+
+ if (is_array($elems)) foreach($elems as $elem) {
+
+ switch($elem['name']) {
+
+ case '{' . Plugin::NS_CARDDAV . '}is-not-defined' :
+ $result['is-not-defined'] = true;
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}text-match' :
+ $matchType = isset($elem['attributes']['match-type'])?$elem['attributes']['match-type']:'contains';
+
+ if (!in_array($matchType, array('contains', 'equals', 'starts-with', 'ends-with'))) {
+ throw new BadRequest('Unknown match-type: ' . $matchType);
+ }
+ $result['text-match'] = [
+ 'negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition']==='yes',
+ 'collation' => isset($elem['attributes']['collation'])?$elem['attributes']['collation']:'i;unicode-casemap',
+ 'value' => $elem['value'],
+ 'match-type' => $matchType,
+ ];
+ break;
+
+ }
+
+ }
+
+ return $result;
+
+ }
+
+}
diff --git a/lib/CardDAV/Xml/Filter/PropFilter.php b/lib/CardDAV/Xml/Filter/PropFilter.php
new file mode 100644
index 0000000..a7cbf8e
--- /dev/null
+++ b/lib/CardDAV/Xml/Filter/PropFilter.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Sabre\CardDAV\XML\Filter;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotSerialize,
+ Sabre\DAV\Exception\BadRequest,
+ Sabre\CardDAV\Plugin;
+
+
+/**
+ * PropFilter parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}prop-filter XML
+ * element, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-10.5.1
+ *
+ * The result will be spit out as an array.
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class PropFilter implements Element {
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ throw new CannotSerialize('This element cannot be serialized.');
+
+ }
+
+ /**
+ * 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.
+ *
+ * Important note 2: 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 public function deserializeXml(Reader $reader) {
+
+ $result = [
+ 'name' => null,
+ 'test' => 'anyof',
+ 'is-not-defined' => false,
+ 'param-filters' => [],
+ 'text-matches' => [],
+ ];
+
+ $att = $reader->parseAttributes();
+ $result['name'] = $att['name'];
+
+ if (isset($att['test']) && $att['test']==='allof') {
+ $result['test'] = 'allof';
+ }
+
+ $elems = $reader->parseInnerTree();
+
+ if (is_array($elems)) foreach($elems as $elem) {
+
+ switch($elem['name']) {
+
+ case '{' . Plugin::NS_CARDDAV . '}param-filter' :
+ $result['param-filters'][] = $elem['value'];
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}is-not-defined' :
+ $result['is-not-defined'] = true;
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}text-match' :
+ $matchType = isset($elem['attributes']['match-type'])?$elem['attributes']['match-type']:'contains';
+
+ if (!in_array($matchType, array('contains', 'equals', 'starts-with', 'ends-with'))) {
+ throw new BadRequest('Unknown match-type: ' . $matchType);
+ }
+ $result['text-matches'][] = [
+ 'negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition']==='yes',
+ 'collation' => isset($elem['attributes']['collation'])?$elem['attributes']['collation']:'i;unicode-casemap',
+ 'value' => $elem['value'],
+ 'match-type' => $matchType,
+ ];
+ break;
+
+ }
+
+ }
+
+ return $result;
+
+ }
+
+}
diff --git a/lib/CardDAV/Xml/Property/SupportedAddressData.php b/lib/CardDAV/Xml/Property/SupportedAddressData.php
new file mode 100644
index 0000000..88caa51
--- /dev/null
+++ b/lib/CardDAV/Xml/Property/SupportedAddressData.php
@@ -0,0 +1,108 @@
+<?php
+
+namespace Sabre\CardDAV\XML\Property;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotDeserialize,
+ Sabre\CardDAV\Plugin;
+
+/**
+ * Supported-address-data property
+ *
+ * This property is a representation of the supported-address-data property
+ * in the CardDAV namespace.
+ *
+ * This property is defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-6.2.2
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class SupportedAddressData implements Element {
+
+ /**
+ * supported versions
+ *
+ * @var array
+ */
+ protected $supportedData = array();
+
+ /**
+ * Creates the property
+ *
+ * @param array|null $supportedData
+ */
+ public function __construct(array $supportedData = null) {
+
+ if (is_null($supportedData)) {
+ $supportedData = array(
+ array('contentType' => 'text/vcard', 'version' => '3.0'),
+ // array('contentType' => 'text/vcard', 'version' => '4.0'),
+ );
+ }
+
+ $this->supportedData = $supportedData;
+
+ }
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ foreach($this->supportedData as $supported) {
+ $writer->startElement('{' . Plugin::NS_CARDDAV . '}address-data-type');
+ $writer->writeAttributes([
+ 'content-type' => $supported['contentType'],
+ 'version' => $supported['version']
+ ]);
+ $writer->endElement(); // address-data-type
+ }
+
+ }
+
+ /**
+ * 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.
+ *
+ * Important note 2: 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 public function deserializeXml(Reader $reader) {
+
+ throw new CannotDeserialize('This element does not have a deserializer');
+
+ }
+
+}
diff --git a/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php b/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php
new file mode 100644
index 0000000..60c32f5
--- /dev/null
+++ b/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php
@@ -0,0 +1,114 @@
+<?php
+
+namespace Sabre\CardDAV\XML\Request;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotSerialize,
+ Sabre\CardDAV\Plugin;
+
+/**
+ * AddressBookMultiGetReport request parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-multiget
+ * REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-8.7
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class AddressBookMultiGetReport implements Element {
+
+ /**
+ * An array with requested properties.
+ *
+ * @var array
+ */
+ public $properties;
+
+ /**
+ * This is an array with the urls that are being requested.
+ *
+ * @var array
+ */
+ public $hrefs;
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ throw new CannotSerialize('This element cannot be serialized.');
+
+ }
+
+ /**
+ * 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.
+ *
+ * Important note 2: 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 public function deserializeXml(Reader $reader) {
+
+ $elems = $reader->parseInnerTree();
+ $hrefs = [];
+
+ $properties = null;
+
+ $expand = false;
+
+ foreach($elems as $elem) {
+
+ switch($elem['name']) {
+
+ case '{DAV:}prop' :
+ $properties = array_keys($elem['value']);
+ break;
+ case '{DAV:}href' :
+ $hrefs[] = $elem['value'];
+ break;
+
+ }
+
+ }
+
+ $obj = new self();
+ $obj->properties = $properties;
+ $obj->hrefs = $hrefs;
+
+ return $obj;
+
+ }
+
+}
diff --git a/lib/CardDAV/Xml/Request/AddressBookQueryReport.php b/lib/CardDAV/Xml/Request/AddressBookQueryReport.php
new file mode 100644
index 0000000..6badc10
--- /dev/null
+++ b/lib/CardDAV/Xml/Request/AddressBookQueryReport.php
@@ -0,0 +1,171 @@
+<?php
+
+namespace Sabre\CardDAV\XML\Request;
+
+use
+ Sabre\XML\Element,
+ Sabre\XML\Reader,
+ Sabre\XML\Writer,
+ Sabre\DAV\Exception\CannotSerialize,
+ Sabre\DAV\Exception\BadRequest,
+ Sabre\CardDAV\Plugin;
+
+/**
+ * AddressBookQueryReport request parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-query
+ * REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-8.6
+ *
+ * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class AddressBookQueryReport implements Element {
+
+ /**
+ * An array with requested properties.
+ *
+ * @var array
+ */
+ public $properties;
+
+ /**
+ * List of property/component filters.
+ *
+ * @var array
+ */
+ public $filter;
+
+ /**
+ * The number of results the client wants
+ *
+ * null means it wasn't specified, which in most cases means 'all results'.
+ *
+ * @var int|null
+ */
+ public $limit;
+
+ /**
+ * Either 'anyof' or 'allof'
+ *
+ * @var string
+ */
+ public $test;
+
+ /**
+ * The serialize method is called during xml writing.
+ *
+ * It should use the $writer argument to encode this object into XML.
+ *
+ * Important note: it is not needed to create the parent element. The
+ * parent element is already created, and we only have to worry about
+ * attributes, child elements and text (if any).
+ *
+ * Important note 2: If you are writing any new elements, you are also
+ * responsible for closing them.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ public function serializeXml(Writer $writer) {
+
+ throw new CannotSerialize('This element cannot be serialized.');
+
+ }
+
+ /**
+ * 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.
+ *
+ * Important note 2: 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 public function deserializeXml(Reader $reader) {
+
+ $elems = $reader->parseInnerTree();
+
+ $properties = null;
+ $filter = null;
+ $test = 'anyof';
+ $limit = null;
+
+ if (!is_array($elems)) $elems = [];
+
+ foreach($elems as $elem) {
+
+ switch($elem['name']) {
+
+ case '{DAV:}prop' :
+ $properties = array_keys($elem['value']);
+ break;
+ case '{'.Plugin::NS_CARDDAV.'}filter' :
+
+ if (!is_null($filter)) {
+ throw new BadRequest('You can only include 1 {' . Plugin::NS_CARDDAV . '}filter element');
+ }
+ if (isset($elem['attributes']['test'])) {
+ $test = $elem['attributes']['test'];
+ if ($test!=='allof' && $test!=='anyof') {
+ throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"');
+ }
+ }
+
+ foreach($elem['value'] as $subElem) {
+ if ($subElem['name'] === '{' . Plugin::NS_CARDDAV . '}prop-filter') {
+ if (is_null($filter)) {
+ $filter = [];
+ }
+ $filter[] = $subElem['value'];
+ }
+ }
+ break;
+ case '{'.Plugin::NS_CARDDAV.'}limit' :
+ foreach($elem['value'] as $child) {
+ if ($child['name'] === '{'. Plugin::NS_CARDDAV .'}nresults') {
+ $limit = (int)$child['value'];
+ }
+ }
+ break;
+
+ }
+
+ }
+
+ if (is_null($filter)) {
+ /**
+ * We are supposed to throw this error, but KDE sometimes does not
+ * include the filter element, and we need to treat it as if no
+ * filters are supplied
+ */
+ //throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request');
+ $filter = [];
+
+ }
+
+ $obj = new self();
+ $obj->properties = $properties;
+ $obj->filter = $filter;
+ $obj->test = $test;
+ $obj->limit = $limit;
+
+ return $obj;
+
+ }
+
+}
--
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