[Pkg-owncloud-commits] [php-sabre-vobject] 178/341: Refactor: split `parseVCalendarComponents`.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:45 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 46322553efd965a349c7725459d64c6c2f7d81fd
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Wed Jan 21 15:28:34 2015 +0100

    Refactor: split `parseVCalendarComponents`.
    
    Create `parseProperty` and `parseComponent` methods.
---
 lib/Parser/XML.php | 218 +++++++++++++++++++++++++++++------------------------
 1 file changed, 119 insertions(+), 99 deletions(-)

diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php
index 820807e..9242793 100644
--- a/lib/Parser/XML.php
+++ b/lib/Parser/XML.php
@@ -103,29 +103,25 @@ class XML extends Parser {
      * @param Sabre\VObject\Component $parentComponent
      * @return void
      */
-    protected function parseVcalendarComponents(Component $parentComponent) {
+    protected function parseVCalendarComponents(Component $parentComponent) {
 
         foreach ($this->pointer['value'] ?: [] as $children) {
 
             switch (static::getTagName($children['name'])) {
 
                 case 'properties':
-                    $xmlProperties = $children['value'];
-
-                    foreach ($xmlProperties as $xmlProperty) {
-
-                        $propertyName       = static::getTagName($xmlProperty['name']);
-                        $propertyValue      = [];
-                        $propertyParameters = [];
-                        $propertyType       = 'text';
-
-                        foreach ($xmlProperty['value'] as $i => $xmlPropertyChild) {
+                    $this->pointer = &$children['value'];
+                    $this->parseProperty($parentComponent);
+                    break;
 
-                            if (   !is_array($xmlPropertyChild)
-                                || 'parameters' !== static::getTagName($xmlPropertyChild['name']))
-                                continue;
+                case 'components':
+                    $this->pointer = &$children;
+                    $this->parseComponent($parentComponent);
+                    break;
+            }
+        }
 
-                            $xmlParameters = $xmlPropertyChild['value'];
+    }
 
                             foreach ($xmlParameters as $xmlParameter) {
                                 $propertyParameters[static::getTagName($xmlParameter['name'])]
@@ -136,103 +132,127 @@ class XML extends Parser {
 
                         }
 
-                        switch ($propertyName) {
-
-                            case 'geo':
-                                $propertyType               = 'float';
-                                $propertyValue['latitude']  = 0;
-                                $propertyValue['longitude'] = 0;
-
-                                foreach ($xmlProperty['value'] as $xmlRequestChild) {
-                                    $propertyValue[static::getTagName($xmlRequestChild['name'])]
-                                        = $xmlRequestChild['value'];
-                                }
-                                break;
-
-                            case 'request-status':
-                                $propertyType = 'text';
-
-                                foreach ($xmlProperty['value'] as $xmlRequestChild) {
-                                    $propertyValue[static::getTagName($xmlRequestChild['name'])]
-                                        = $xmlRequestChild['value'];
-                                }
-                                break;
-
-                            case 'freebusy':
-                                $propertyType = 'freebusy';
-                                // We don't break because we only want to set
-                                // another property type.
-
-                            case 'categories':
-                            case 'resources':
-                            case 'exdate':
-                                foreach ($xmlProperty['value'] as $specialChild) {
-                                    $propertyValue[static::getTagName($specialChild['name'])]
-                                        = $specialChild['value'];
-                                }
-                                break;
-
-                            case 'rdate':
-                                $propertyType = 'date-time';
-
-                                foreach ($xmlProperty['value'] as $specialChild) {
-
-                                    $tagName = static::getTagName($specialChild['name']);
-
-                                    if ('period' === $tagName) {
-
-                                        $propertyParameters['value'] = 'PERIOD';
-                                        $propertyValue[]             = implode('/', $specialChild['value']);
-
-                                    }
-                                    else {
-                                        $propertyValue[] = $specialChild['value'];
-                                    }
-                                }
-                                break;
-
-                            default:
-                                $propertyType  = static::getTagName($xmlProperty['value'][0]['name']);
-                                $propertyValue = [$xmlProperty['value'][0]['value']];
-
-                                if ('date' === $propertyType) {
-                                    $propertyParameters['value'] = 'DATE';
-                                }
-                                break;
-                        }
+    protected function parseProperty(Component $parentComponent) {
+
+        foreach ($this->pointer as $xmlProperty) {
+
+            $propertyName       = static::getTagName($xmlProperty['name']);
+            $propertyValue      = [];
+            $propertyParameters = [];
+            $propertyType       = 'text';
 
-                        $property = $this->root->createProperty(
-                            $propertyName,
-                            null,
-                            $propertyParameters,
-                            $propertyType
-                        );
-                        $parentComponent->add($property);
-                        $property->setXmlValue($propertyValue);
+            foreach ($xmlProperty['value'] as $i => $xmlPropertyChild) {
+
+                if (   !is_array($xmlPropertyChild)
+                    || 'parameters' !== static::getTagName($xmlPropertyChild['name']))
+                    continue;
+
+                foreach ($xmlParameters as $xmlParameter) {
+                    $propertyParameters[static::getTagName($xmlParameter['name'])]
+                        = $xmlParameter['value'][0]['value'];
+                }
+
+                array_splice($xmlProperty['value'], $i, 1);
+
+            }
+
+            switch ($propertyName) {
+
+                case 'geo':
+                    $propertyType               = 'float';
+                    $propertyValue['latitude']  = 0;
+                    $propertyValue['longitude'] = 0;
+
+                    foreach ($xmlProperty['value'] as $xmlRequestChild) {
+                        $propertyValue[static::getTagName($xmlRequestChild['name'])]
+                            = $xmlRequestChild['value'];
                     }
                     break;
 
-                case 'components':
-                    $components = $children['value'] ?: [];
+                case 'request-status':
+                    $propertyType = 'text';
+
+                    foreach ($xmlProperty['value'] as $xmlRequestChild) {
+                        $propertyValue[static::getTagName($xmlRequestChild['name'])]
+                            = $xmlRequestChild['value'];
+                    }
+                    break;
+
+                case 'freebusy':
+                    $propertyType = 'freebusy';
+                    // We don't break because we only want to set
+                    // another property type.
+
+                case 'categories':
+                case 'resources':
+                case 'exdate':
+                    foreach ($xmlProperty['value'] as $specialChild) {
+                        $propertyValue[static::getTagName($specialChild['name'])]
+                            = $specialChild['value'];
+                    }
+                    break;
+
+                case 'rdate':
+                    $propertyType = 'date-time';
+
+                    foreach ($xmlProperty['value'] as $specialChild) {
 
-                    foreach ($components as $component) {
+                        $tagName = static::getTagName($specialChild['name']);
 
-                        $componentName    = static::getTagName($component['name']);
-                        $currentComponent = $this->root->createComponent(
-                            $componentName,
-                            null,
-                            false
-                        );
+                        if ('period' === $tagName) {
 
-                        $this->pointer = &$component;
-                        $this->parseVcalendarComponents($currentComponent);
+                            $propertyParameters['value'] = 'PERIOD';
+                            $propertyValue[]             = implode('/', $specialChild['value']);
 
-                        $parentComponent->add($currentComponent);
+                        }
+                        else {
+                            $propertyValue[] = $specialChild['value'];
+                        }
+                    }
+                    break;
+
+                default:
+                    $propertyType  = static::getTagName($xmlProperty['value'][0]['name']);
+                    $propertyValue = [$xmlProperty['value'][0]['value']];
 
+                    if ('date' === $propertyType) {
+                        $propertyParameters['value'] = 'DATE';
                     }
                     break;
             }
+
+            $property = $this->root->createProperty(
+                $propertyName,
+                null,
+                $propertyParameters,
+                $propertyType
+            );
+            $parentComponent->add($property);
+            $property->setXmlValue($propertyValue);
         }
+
+    }
+
+    protected function parseComponent(Component $parentComponent) {
+
+        $components = $this->pointer['value'] ?: [];
+
+        foreach ($components as $component) {
+
+            $componentName    = static::getTagName($component['name']);
+            $currentComponent = $this->root->createComponent(
+                $componentName,
+                null,
+                false
+            );
+
+            $this->pointer = &$component;
+            $this->parseVCalendarComponents($currentComponent);
+
+            $parentComponent->add($currentComponent);
+
+        }
+
     }
 
     /**

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