[Pkg-owncloud-commits] [php-sabre-vobject] 51/341: !xml Refactor and compute each type individually…

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:32 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 ff5fd149a01a14a953b32cb48d10250944b326ba
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Mon Nov 17 12:12:53 2014 +0100

    !xml Refactor and compute each type individually…
    
    … because there is some subtle differences between xCal and iCalendar
    (see Section 3.6. Values of the RFC6321).
---
 lib/Parser/XML.php | 163 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 149 insertions(+), 14 deletions(-)

diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php
index ccec66f..e7e59a2 100644
--- a/lib/Parser/XML.php
+++ b/lib/Parser/XML.php
@@ -6,7 +6,8 @@ use
     Sabre\VObject\Component\VCalendar,
     Sabre\VObject\Component\VCard,
     Sabre\VObject\EofException,
-    Sabre\XML as SabreXML;
+    Sabre\XML as SabreXML,
+    DateTime;
 
 /**
  * XML Parser.
@@ -73,23 +74,157 @@ class XML extends Parser {
 
             switch(static::getTagName($children['name'])) {
 
+                // Properties.
                 case 'properties':
-                    $properties = $children['value'];
+                    $xmlProperties = $children['value'];
 
-                    foreach($properties as $property) {
+                    foreach($xmlProperties as $xmlProperty) {
 
-                        $propertyName  = static::getTagName($property['name']);
-                        $propertyValue = $property['value'][0]['value'];
-                        $propertyType  = static::getTagName($property['value'][0]['name']);
-
-                        $parentComponent->add(
-                            $this->root->createProperty(
-                                $propertyName,
-                                $propertyValue,
-                                array(),
-                                $propertyType
-                            )
+                        // Property.
+                        $propertyName = static::getTagName($xmlProperty['name']);
+                        $property     = $this->root->createProperty(
+                            $propertyName
                         );
+
+                        /*
+                        switch($propertyName) {
+
+                            // special cases
+                            case 'categories':
+                            case 'resources':
+                            case 'freebusy':
+                            case 'exdate':
+                            case 'rdate':
+                              break;
+
+                            case 'geo':
+                              break;
+
+                            case 'request-status':
+                              break;
+
+                            default:
+                              break;
+                        }
+                        */
+
+                        foreach($xmlProperty['value'] as $xmlPropertyChildren) {
+
+                            $xmlPropertyName = static::getTagName($xmlPropertyChildren['name']);
+
+                            // Parameters.
+                            if('parameters' === $xmlPropertyName) {
+
+                                // parameters
+                                // 3.5 of the RFC
+
+                                continue;
+                            }
+
+                            // Property type and value(s).
+                            $propertyType     = $xmlPropertyName;
+                            $xmlPropertyValue = $xmlPropertyChildren['value'];
+
+                            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
+                                        // TODO: TimeZone? TZID
+                                    ));
+                                  break;
+
+                                case 'date-time':
+                                    $xmlPropertyValue = rtrim($xmlPropertyValue, 'Z');
+                                    $property->setValue(DateTime::createFromFormat(
+                                        'Y-m-d\TH:i:s',
+                                        $xmlPropertyValue
+                                        // TODO: TimeZone? TZID
+                                    ));
+                                  break;
+
+                                case 'period':
+                                    $periodStart         = null;
+                                    $periodEndOrDuration = null;
+
+                                    foreach($xmlPropertyValue as $xmlPeriodChildren) {
+
+                                        $xmlPeriodValue = $xmlPeriodChildren['value'];
+
+                                        switch(static::getTagName($xmlPeriodChildren['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 $xmlRecurChildren) {
+
+                                        $xmlRecurName  = static::getTagName($xmlRecurChildren['name']);
+                                        $xmlRecurValue = $xmlRecurChildren['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;
+                            }
+                        }
+
+                        $parentComponent->add($property);
                     }
                     break;
 

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