[Pkg-owncloud-commits] [php-sabre-vobject] 73/341: !xml #19 on sabre/xml has been closed.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:35 UTC 2015


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

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

commit f51225c9d73e30fb74fdd75cabf7f705b3b1a9c5
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Tue Nov 18 17:26:36 2014 +0100

    !xml #19 on sabre/xml has been closed.
---
 lib/Parser/XML/Element/KeyValue.php | 49 +++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/lib/Parser/XML/Element/KeyValue.php b/lib/Parser/XML/Element/KeyValue.php
index dbf6c7c..4be1e85 100644
--- a/lib/Parser/XML/Element/KeyValue.php
+++ b/lib/Parser/XML/Element/KeyValue.php
@@ -16,14 +16,53 @@ use Sabre\XML as SabreXML;
 class KeyValue extends SabreXML\Element\KeyValue {
 
     /**
-     * Get element name.
+     * The deserialize method is called during xml parsing.
      *
-     * @param SabreXML\Reader $reader
-     * @return string
+     * This method is called staticly, 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 XML\Reader $reader
+     * @return mixed
      */
-    static function getElementName(SabreXML\Reader $reader) {
+    static function deserializeXml(SabreXML\Reader $reader) {
+
+        // If there's no children, we don't do anything.
+        if ($reader->isEmptyElement) {
+            $reader->next();
+            return [];
+        }
+
+        $values = [];
+        $reader->read();
+
+        do {
+
+            if ($reader->nodeType === SabreXML\Reader::ELEMENT) {
+
+                $name = $reader->localName;
+                $values[$name] = $reader->parseCurrentElement()['value'];
+
+            } else {
+                $reader->read();
+            }
+
+        } while ($reader->nodeType !== SabreXML\Reader::END_ELEMENT);
+
+        $reader->read();
 
-        return $reader->localName;
+        return $values;
 
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list