[Pkg-owncloud-commits] [php-sabre-vobject] 155/341: Pass the XML writer instead of dealing with arrays.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:43 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 beebbb3b0c2989f33ca33a53a5daeb2224285caf
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Mon Jan 19 14:23:07 2015 +0100

    Pass the XML writer instead of dealing with arrays.
---
 lib/Component.php      | 53 +++++++++++++++++++++--------------
 lib/Node.php           | 11 +++++---
 lib/Parameter.php      | 12 ++++----
 lib/Property.php       | 75 +++++++++++++++++++++++++++++++-------------------
 lib/Property/Float.php | 27 +++++++++---------
 lib/Property/Text.php  | 27 +++++++++---------
 lib/Writer.php         |  3 +-
 7 files changed, 121 insertions(+), 87 deletions(-)

diff --git a/lib/Component.php b/lib/Component.php
index 12854a0..9277759 100644
--- a/lib/Component.php
+++ b/lib/Component.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\VObject;
 
+use Sabre\Xml;
+
 /**
  * Component
  *
@@ -346,42 +348,51 @@ class Component extends Node {
     }
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes the data into XML. This is used to create xCard or
+     * xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    function xmlSerialize() {
+    function xmlSerialize(Xml\Writer $writer) {
 
         $components = [];
         $properties = [];
 
         foreach($this->children as $child) {
             if ($child instanceof Component) {
-                $components[] = $child->xmlSerialize()[0];
+                $components[] = $child;
             } else {
-                $properties[] = $child->xmlSerialize();
+                $properties[] = $child;
             }
         }
 
-        $out = [
-            'name' => strtolower($this->name),
-            'value' => []
-        ];
+        $writer->startElement(strtolower($this->name));
+
+        if (!empty($properties)) {
+
+            $writer->startElement('properties');
+
+            foreach ($properties as $property) {
+                $property->xmlSerialize($writer);
+            }
+
+            $writer->endElement();
+
+        }
 
-        if(!empty($properties))
-            $out['value'][] = [
-                'name' => 'properties',
-                'value' => $properties
-            ];
+        if (!empty($components)) {
 
-        if(!empty($components))
-            $out['value'][] = [
-                'name' => 'components',
-                'value' => $components
-            ];
+            $writer->startElement('components');
+
+            foreach ($components as $component) {
+                $component->xmlSerialize($writer);
+            }
+
+            $writer->endElement();
+        }
 
-        return [$out];
+        $writer->endElement();
 
     }
 
diff --git a/lib/Node.php b/lib/Node.php
index 3ac15b5..633575a 100644
--- a/lib/Node.php
+++ b/lib/Node.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\VObject;
 
+use Sabre\Xml;
+
 /**
  * A node is the root class for every element in an iCalendar of vCard object.
  *
@@ -78,12 +80,13 @@ abstract class Node
     abstract function jsonSerialize();
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes the data into XML. This is used to create xCard or
+     * xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    abstract function xmlSerialize();
+    abstract function xmlSerialize(Xml\Writer $writer);
 
     /* {{{ IteratorAggregator interface */
 
diff --git a/lib/Parameter.php b/lib/Parameter.php
index dbd0931..6fabd0f 100644
--- a/lib/Parameter.php
+++ b/lib/Parameter.php
@@ -3,6 +3,7 @@
 namespace Sabre\VObject;
 
 use
+    Sabre\Xml,
     ArrayIterator;
 
 /**
@@ -346,14 +347,15 @@ class Parameter extends Node {
     }
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes the data into XML. This is used to create xCard or
+     * xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    function xmlSerialize() {
+    function xmlSerialize(Xml\Writer $writer) {
 
-        return $this->value;
+        $writer->write($this->value);
 
     }
 
diff --git a/lib/Property.php b/lib/Property.php
index e4a696a..6cbcc09 100644
--- a/lib/Property.php
+++ b/lib/Property.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\VObject;
 
+use Sabre\Xml;
+
 /**
  * Property
  *
@@ -347,50 +349,67 @@ abstract class Property extends Node {
     }
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes the data into XML. This is used to create xCard or
+     * xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    function xmlSerialize() {
+    function xmlSerialize(Xml\Writer $writer) {
 
         $parameters = [];
 
         foreach($this->parameters as $parameter) {
+
             if ($parameter->name === 'VALUE') {
                 continue;
             }
-            $parameters[] = [
-                'name' => strtolower($parameter->name),
-                'value' => [
-                    [
-                        'name' => 'text',
-                        'value' => $parameter->xmlSerialize()
-                    ]
-                ]
-            ];
+
+            $parameters[] = $parameter;
+
         }
 
-        $properties = [
-            'name' => strtolower($this->name),
-            'value' => []
-        ];
+        $writer->startElement(strtolower($this->name));
 
-        if(!empty($parameters))
-            $properties['value'][] = [
-                'name' => 'parameters',
-                'value' => $parameters
-            ];
+        if (!empty($parameters)) {
+
+            $writer->startElement('parameters');
+
+            foreach ($parameters as $parameter) {
+
+                $writer->startElement(strtolower($parameter->name));
+                    $writer->startElement('text');
+                        $parameter->xmlSerialize($writer);
+                    $writer->endElement();
+                $writer->endElement();
+
+            }
+
+            $writer->endElement();
 
-        foreach ($this->getXmlValue() as $value) {
-            $properties['value'][] = [
-                'name' => strtolower($this->getValueType()),
-                'value' => $value
-            ];
         }
 
+        $this->xmlSerializeValue($writer);
+        $writer->endElement();
+
+    }
+
+    /**
+     * This method serializes only the value of a property. This is used to
+     * create xCard or xCal documents.
+     *
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
+     */
+    protected function xmlSerializeValue(Xml\Writer $writer) {
+
+        foreach ($this->getXmlValue() as $value) {
+
+            $writer->startElement(strtolower($this->getValueType()));
+                $writer->write($value);
+            $writer->endElement();
 
-        return $properties;
+        }
 
     }
 
diff --git a/lib/Property/Float.php b/lib/Property/Float.php
index d08254a..1b2560b 100644
--- a/lib/Property/Float.php
+++ b/lib/Property/Float.php
@@ -3,7 +3,8 @@
 namespace Sabre\VObject\Property;
 
 use
-    Sabre\VObject\Property;
+    Sabre\VObject\Property,
+    Sabre\Xml;
 
 /**
  * Float property
@@ -145,28 +146,26 @@ class Float extends Property {
     }
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes only the value of a property. This is used to
+     * create xCard or xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    function xmlSerialize() {
-
-        $serialization = parent::xmlSerialize();
+    protected function xmlSerializeValue(Xml\Writer $writer) {
 
         // Special-casing the GEO property.
         //
         // See:
         // http://tools.ietf.org/html/rfc6321#section-3.4.1.2
         if ($this->name === 'GEO') {
-
-            $handle = $serialization['value'][0]['value'];
-            $serialization['value'] = $handle;
-            return $serialization;
-
+            foreach ($this->getXmlValue() as $value) {
+                $writer->write($value);
+            }
+        }
+        else {
+            parent::xmlSerializeValue($writer);
         }
-
-        return $serialization;
 
     }
 
diff --git a/lib/Property/Text.php b/lib/Property/Text.php
index 18e60fd..6e0167a 100644
--- a/lib/Property/Text.php
+++ b/lib/Property/Text.php
@@ -6,7 +6,8 @@ use
     Sabre\VObject\Property,
     Sabre\VObject\Component,
     Sabre\VObject\Parser\MimeDir,
-    Sabre\VObject\Document;
+    Sabre\VObject\Document,
+    Sabre\Xml;
 
 /**
  * Text property
@@ -329,28 +330,26 @@ class Text extends Property {
     }
 
     /**
-     * This method returns an array, with the representation as it should be
-     * encoded in XML. This is used to create xCard or xCal documents.
+     * This method serializes only the value of a property. This is used to
+     * create xCard or xCal documents.
      *
-     * @return array
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
      */
-    function xmlSerialize() {
-
-        $serialization = parent::xmlSerialize();
+    protected function xmlSerializeValue(Xml\Writer $writer) {
 
         // Special-casing the REQUEST-STATUS property.
         //
         // See:
         // http://tools.ietf.org/html/rfc6321#section-3.4.1.3
         if ($this->name === 'REQUEST-STATUS') {
-
-            $handle = $serialization['value'][0]['value'];
-            $serialization['value'] = $handle;
-            return $serialization;
-
+            foreach ($this->getXmlValue() as $value) {
+                $writer->write($value);
+            }
+        }
+        else {
+            parent::xmlSerializeValue($writer);
         }
-
-        return $serialization;
 
     }
 
diff --git a/lib/Writer.php b/lib/Writer.php
index 8c95bca..db1a14b 100644
--- a/lib/Writer.php
+++ b/lib/Writer.php
@@ -65,7 +65,8 @@ class Writer {
         }
 
         $writer->setIndent(true);
-        $writer->write($component->xmlSerialize());
+
+        $component->xmlSerialize($writer);
 
         $writer->endElement();
 

-- 
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