[Pkg-owncloud-commits] [php-sabre-vobject] 58/341: !xml Dispatch property computation in each object.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:33 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 ce30b6fcaa0aee45b95f4aa26696de3a66736cdc
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Tue Nov 18 11:02:13 2014 +0100

    !xml Dispatch property computation in each object.
---
 lib/Parser/XML.php | 232 +++++------------------------------------------------
 lib/Property.php   |  43 +++++++++-
 2 files changed, 59 insertions(+), 216 deletions(-)

diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php
index 7a540b2..9610cac 100644
--- a/lib/Parser/XML.php
+++ b/lib/Parser/XML.php
@@ -74,231 +74,37 @@ class XML extends Parser {
 
             switch(static::getTagName($children['name'])) {
 
-                // Properties.
                 case 'properties':
                     $xmlProperties = $children['value'];
 
                     foreach($xmlProperties as $xmlProperty) {
 
-                        // Property.
-                        $property            = null;
-                        $propertyName        = static::getTagName($xmlProperty['name']);
-                        $xmlPropertyChildren = $xmlProperty['value'];
-
-//                        // special cases
-//                        switch($propertyName) {
-//
-//                            /*
-//                            case 'categories':
-//                            case 'resources':
-//                            case 'freebusy':
-//                            case 'exdate':
-//                            case 'rdate':
-//                              break;
-//                            */
-//
-//                            case 'geo':
-//                                $latitude = null;
-//                                $longitude = null;
-//
-//                                foreach($xmlPropertyChildren as $xmlGeoChild) {
-//
-//                                    $xmlGeoValue = $xmlGeoChild['value'];
-//
-//                                    switch(static::getTagName($xmlGeoChild['name'])) {
-//
-//                                        case 'latitude':
-//                                            $latitude = $xmlGeoValue;
-//                                          break;
-//
-//                                        case 'longitude':
-//                                            $longitude = $xmlGeoValue;
-//                                          break;
-//
-//                                        default:
-//                                            // TODO: EXCEPTION
-//                                          break;
-//                                    }
-//                                }
-//
-//                                $property->setRawMimeDirValue(
-//                                    $latitude .
-//                                    ';' .
-//                                    $longitude
-//                                );
-//                              break 2;
-//
-//                            case 'request-status':
-//                                $requestChildren = [
-//                                    0 => null,
-//                                    1 => null
-//                                ];
-//
-//                                foreach($xmlPropertyChildren as $xmlRequestChild) {
-//
-//                                    $xmlRequestValue = $xmlRequestChild['value'];
-//
-//                                    switch(static::getTagName($xmlRequestChild['name'])) {
-//
-//                                        case 'code':
-//                                            $requestChildren[0] = $xmlRequestValue;
-//                                          break;
-//
-//                                        case 'description':
-//                                            $requestChildren[1] = $xmlRequestValue;
-//                                          break;
-//
-//                                        case 'data':
-//                                            $requestChildren[2] = $xmlRequestValue;
-//                                          break;
-//
-//                                        default:
-//                                            // TODO: EXCEPTION
-//                                          break;
-//                                    }
-//                                }
-//
-//                                $property->setParts($requestChildren);
-//                              break 2;
-//
-//                            default:
-//                              break;
-//                        }
-
+                        $propertyName       = static::getTagName($xmlProperty['name']);
                         $propertyParameters = [];
 
-                        foreach($xmlPropertyChildren as $xmlPropertyChild) {
-
-                            $xmlPropertyChildName = static::getTagName($xmlPropertyChild['name']);
+                        foreach($xmlProperty['value'] as $xmlPropertyChild) {
 
-                            // Parameters.
-                            if('parameters' === $xmlPropertyChildName) {
-
-                                $xmlParameters = $xmlPropertyChild['value'];
+                            if('parameters' !== static::getTagName($xmlPropertyChild['name']))
+                                continue;
 
-                                foreach($xmlParameters as $xmlParameter)
-                                    $propertyParameters[static::getTagName($xmlParameter['name'])]
-                                        = $xmlParameter['value'][0]['value'];
+                            $xmlParameters = $xmlPropertyChild['value'];
 
-                                continue;
-                            }
-
-                            // Property type and value(s).
-                            $propertyType     = $xmlPropertyChildName;
-                            $xmlPropertyValue = $xmlPropertyChild['value'];
-                            $property         = $this->root->createProperty(
-                                $propertyName,
-                                null,
-                                null,
-                                $propertyType
-                            );
-                            $parentComponent->add($property);
-                            $defaultPropertyClassName
-                                = $this->root->getClassNameForPropertyName(strtoupper($propertyName));
-
-                            if(get_class($property) !== $defaultPropertyClassName)
-                                $property->add('VALUE', strtoupper($propertyType));
-
-                            switch($propertyType) {
-
-                                case 'binary':
-                                case 'boolean':
-                                case 'duration':
-                                case 'float':
-                                case 'integer':
-                                    $property->setRawMimeDirValue($xmlPropertyValue);
-                                  break;
-
-                                case 'cal-address':
-                                case 'text':
-                                case 'uri':
-                                    $property->setValue($xmlPropertyValue);
-                                  break;
-
-                                case 'date':
-                                    $property->setValue(DateTime::createFromFormat(
-                                        'Y-m-d',
-                                        $xmlPropertyValue
-                                    ));
-                                  break;
-
-                                case 'date-time':
-                                    $xmlPropertyValue = rtrim($xmlPropertyValue, 'Z');
-                                    $property->setValue(DateTime::createFromFormat(
-                                        'Y-m-d\TH:i:s',
-                                        $xmlPropertyValue
-                                    ));
-                                  break;
-
-                                case 'period':
-                                    $periodStart         = null;
-                                    $periodEndOrDuration = null;
-
-                                    foreach($xmlPropertyValue as $xmlPeriodChild) {
-
-                                        $xmlPeriodValue = $xmlPeriodChild['value'];
-
-                                        switch(static::getTagName($xmlPeriodChild['name'])) {
-
-                                            case 'start':
-                                                $periodStart = $xmlPeriodValue;
-                                              break;
-
-                                            case 'end':
-                                            case 'duration':
-                                                $periodEndOrDuration = $xmlPeriodValue;
-                                              break;
-
-                                            default:
-                                                // TODO: EXCEPTION
-                                              break;
-                                        }
-                                    }
-
-                                    $property->setRawMimeDirValue(
-                                        $periodStart .
-                                        '/' .
-                                        $periodEndOrDuration
-                                    );
-                                  break;
-
-                                case 'recur':
-                                    $recur = [];
-
-                                    foreach($xmlPropertyValue as $xmlRecurChild) {
-
-                                        $xmlRecurName  = static::getTagName($xmlRecurChild['name']);
-                                        $xmlRecurValue = $xmlRecurChild['value'];
-
-                                        if('until' === $xmlRecurName)
-                                            $xmlRecurName = str_replace(
-                                                ['-', ':'],
-                                                '',
-                                                $xmlRecurName
-                                            );
-
-                                        $recur[] = strtoupper($xmlRecurName) .
-                                                   '=' .
-                                                   $xmlRecurValue;
-                                    }
-
-                                    $property->setRawMimeDirValue(
-                                        implode(';', $recur)
-                                    );
-                                  break;
-
-                                case 'time':
-                                case 'utc-offset':
-                                    $property->setValue(
-                                        str_replace(':', '', $xmlPropertyValue)
-                                    );
-                                  break;
-                            }
+                            foreach($xmlParameters as $xmlParameter)
+                                $propertyParameters[static::getTagName($xmlParameter['name'])]
+                                    = $xmlParameter['value'][0]['value'];
                         }
 
-                        if(null !== $property)
-                            foreach($propertyParameters as $name => $value)
-                                $property->add($name, $value);
+                        $propertyType  = $xmlProperty['value'][0]['name'];
+                        $propertyValue = $xmlProperty['value'][0]['value'];
+
+                        $property      = $this->root->createProperty(
+                            $propertyName,
+                            null,
+                            $propertyParameters,
+                            $propertyType
+                        );
+                        $parentComponent->add($property);
+                        $property->setXmlValue([$propertyValue]);
                     }
                     break;
 
diff --git a/lib/Property.php b/lib/Property.php
index 9914b45..5626caf 100644
--- a/lib/Property.php
+++ b/lib/Property.php
@@ -257,7 +257,7 @@ abstract class Property extends Node {
     }
 
     /**
-     * Returns the value, in the format it should be encoded for json.
+     * Returns the value, in the format it should be encoded for JSON.
      *
      * This method must always return an array.
      *
@@ -270,7 +270,7 @@ abstract class Property extends Node {
     }
 
     /**
-     * Sets the json value, as it would appear in a jCard or jCal object.
+     * Sets the JSON value, as it would appear in a jCard or jCal object.
      *
      * The value must always be an array.
      *
@@ -289,7 +289,7 @@ abstract class Property extends Node {
 
     /**
      * This method returns an array, with the representation as it should be
-     * encoded in json. This is used to create jCard or jCal documents.
+     * encoded in JSON. This is used to create jCard or jCal documents.
      *
      * @return array
      */
@@ -319,6 +319,43 @@ abstract class Property extends Node {
         );
     }
 
+    /**
+     * Returns the value, in the format it should be encoded for XML.
+     *
+     * This method must always return an array.
+     *
+     * @return array
+     */
+    function getXmlValue() {
+
+        return $this->getJsonValue();
+
+    }
+
+    /**
+     * Sets the XML value, as it would appear in a xCard or xCal object.
+     *
+     * The value must always be an array.
+     *
+     * @param array $value
+     * @return void
+     */
+    function setXmlValue(array $value) {
+
+        $this->setJsonValue($value);
+
+    }
+
+    /**
+     * This method returns an array, with the representation as it should be
+     * encoded in XML. This is used to create xCard or xCal documents.
+     *
+     * @return array
+     */
+    function xmlSerialize() {
+
+        return $this->jsonSerialize();
+    }
 
     /**
      * Called when this object is being cast to a string.

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