summaryrefslogtreecommitdiffstats
path: root/3rdparty/Sabre/VObject/Component.php
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/Sabre/VObject/Component.php')
-rw-r--r--[-rwxr-xr-x]3rdparty/Sabre/VObject/Component.php136
1 files changed, 88 insertions, 48 deletions
diff --git a/3rdparty/Sabre/VObject/Component.php b/3rdparty/Sabre/VObject/Component.php
index b78a26133fa..7604e3a9bb8 100755..100644
--- a/3rdparty/Sabre/VObject/Component.php
+++ b/3rdparty/Sabre/VObject/Component.php
@@ -1,5 +1,7 @@
<?php
+namespace Sabre\VObject;
+
/**
* VObject Component
*
@@ -7,13 +9,11 @@
* VEVENT, VTODO and also VCALENDAR. It starts with BEGIN:COMPONENTNAME and
* ends with END:COMPONENTNAME
*
- * @package Sabre
- * @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
-class Sabre_VObject_Component extends Sabre_VObject_Element {
+class Component extends Node {
/**
* Name, for example VEVENT
@@ -30,18 +30,20 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
public $children = array();
/**
- * If coponents are added to this map, they will be automatically mapped
+ * If components are added to this map, they will be automatically mapped
* to their respective classes, if parsed by the reader or constructed with
* the 'create' method.
*
* @var array
*/
static public $classMap = array(
- 'VCALENDAR' => 'Sabre_VObject_Component_VCalendar',
- 'VEVENT' => 'Sabre_VObject_Component_VEvent',
- 'VTODO' => 'Sabre_VObject_Component_VTodo',
- 'VJOURNAL' => 'Sabre_VObject_Component_VJournal',
- 'VALARM' => 'Sabre_VObject_Component_VAlarm',
+ 'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
+ 'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar',
+ 'VCARD' => 'Sabre\\VObject\\Component\\VCard',
+ 'VEVENT' => 'Sabre\\VObject\\Component\\VEvent',
+ 'VJOURNAL' => 'Sabre\\VObject\\Component\\VJournal',
+ 'VTODO' => 'Sabre\\VObject\\Component\\VTodo',
+ 'VFREEBUSY' => 'Sabre\\VObject\\Component\\VFreeBusy',
);
/**
@@ -50,7 +52,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*
* @param string $name
* @param string $value
- * @return Sabre_VObject_Component
+ * @return Component
*/
static public function create($name, $value = null) {
@@ -71,9 +73,9 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* be overridden with the iterator argument
*
* @param string $name
- * @param Sabre_VObject_ElementList $iterator
+ * @param ElementList $iterator
*/
- public function __construct($name, Sabre_VObject_ElementList $iterator = null) {
+ public function __construct($name, ElementList $iterator = null) {
$this->name = strtoupper($name);
if (!is_null($iterator)) $this->iterator = $iterator;
@@ -94,40 +96,54 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*
* This is solely used by the childrenSort method.
*
- * A higher score means the item will be higher in the list
+ * A higher score means the item will be lower in the list.
+ * To avoid score collisions, each "score category" has a reasonable
+ * space to accomodate elements. The $key is added to the $score to
+ * preserve the original relative order of elements.
*
- * @param Sabre_VObject_Node $n
+ * @param int $key
+ * @param array $array
* @return int
*/
- $sortScore = function($n) {
+ $sortScore = function($key, $array) {
+
+ if ($array[$key] instanceof Component) {
- if ($n instanceof Sabre_VObject_Component) {
// We want to encode VTIMEZONE first, this is a personal
// preference.
- if ($n->name === 'VTIMEZONE') {
- return 1;
+ if ($array[$key]->name === 'VTIMEZONE') {
+ $score=300000000;
+ return $score+$key;
} else {
- return 0;
+ $score=400000000;
+ return $score+$key;
}
} else {
+ // Properties get encoded first
// VCARD version 4.0 wants the VERSION property to appear first
- if ($n->name === 'VERSION') {
- return 3;
- } else {
- return 2;
+ if ($array[$key] instanceof Property) {
+ if ($array[$key]->name === 'VERSION') {
+ $score=100000000;
+ return $score+$key;
+ } else {
+ // All other properties
+ $score=200000000;
+ return $score+$key;
+ }
}
}
};
- usort($this->children, function($a, $b) use ($sortScore) {
+ $tmp = $this->children;
+ uksort($this->children, function($a, $b) use ($sortScore, $tmp) {
- $sA = $sortScore($a);
- $sB = $sortScore($b);
+ $sA = $sortScore($a, $tmp);
+ $sB = $sortScore($b, $tmp);
if ($sA === $sB) return 0;
- return ($sA > $sB) ? -1 : 1;
+ return ($sA < $sB) ? -1 : 1;
});
@@ -143,8 +159,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*
* You can call this method with the following syntaxes:
*
- * add(Sabre_VObject_Element $element)
- * add(string $name, $value)
+ * add(Node $node)
+ * add(string $name, $value, array $parameters = array())
*
* The first version adds an Element
* The second adds a property as a string.
@@ -153,26 +169,23 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* @param mixed $itemValue
* @return void
*/
- public function add($item, $itemValue = null) {
+ public function add($item, $itemValue = null, array $parameters = array()) {
- if ($item instanceof Sabre_VObject_Element) {
+ if ($item instanceof Node) {
if (!is_null($itemValue)) {
- throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject');
+ throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject Node');
}
$item->parent = $this;
$this->children[] = $item;
} elseif(is_string($item)) {
- if (!is_scalar($itemValue)) {
- throw new InvalidArgumentException('The second argument must be scalar');
- }
- $item = Sabre_VObject_Property::create($item,$itemValue);
+ $item = Property::create($item,$itemValue, $parameters);
$item->parent = $this;
$this->children[] = $item;
} else {
- throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
+ throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string');
}
@@ -181,11 +194,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
/**
* Returns an iterable list of children
*
- * @return Sabre_VObject_ElementList
+ * @return ElementList
*/
public function children() {
- return new Sabre_VObject_ElementList($this->children);
+ return new ElementList($this->children);
}
@@ -218,7 +231,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
if (
strtoupper($child->name) === $name &&
- (is_null($group) || ( $child instanceof Sabre_VObject_Property && strtoupper($child->group) === $group))
+ (is_null($group) || ( $child instanceof Property && strtoupper($child->group) === $group))
) {
$result[$key] = $child;
@@ -241,7 +254,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$result = array();
foreach($this->children as $child) {
- if ($child instanceof Sabre_VObject_Component) {
+ if ($child instanceof Component) {
$result[] = $child;
}
}
@@ -250,6 +263,33 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
}
+ /**
+ * Validates the node for correctness.
+ *
+ * The following options are supported:
+ * - Node::REPAIR - If something is broken, and automatic repair may
+ * be attempted.
+ *
+ * An array is returned with warnings.
+ *
+ * Every item in the array has the following properties:
+ * * level - (number between 1 and 3 with severity information)
+ * * message - (human readable message)
+ * * node - (reference to the offending node)
+ *
+ * @param int $options
+ * @return array
+ */
+ public function validate($options = 0) {
+
+ $result = array();
+ foreach($this->children as $child) {
+ $result = array_merge($result, $child->validate($options));
+ }
+ return $result;
+
+ }
+
/* Magic property accessors {{{ */
/**
@@ -259,7 +299,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* null is returned.
*
* @param string $name
- * @return Sabre_VObject_Property
+ * @return Property
*/
public function __get($name) {
@@ -268,8 +308,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
return null;
} else {
$firstMatch = current($matches);
- /** @var $firstMatch Sabre_VObject_Property */
- $firstMatch->setIterator(new Sabre_VObject_ElementList(array_values($matches)));
+ /** @var $firstMatch Property */
+ $firstMatch->setIterator(new ElementList(array_values($matches)));
return $firstMatch;
}
@@ -291,7 +331,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
/**
* Using the setter method you can add properties or subcomponents
*
- * You can either pass a Sabre_VObject_Component, Sabre_VObject_Property
+ * You can either pass a Component, Property
* object, or a string to automatically create a Property.
*
* If the item already exists, it will be removed. If you want to add
@@ -306,7 +346,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$matches = $this->select($name);
$overWrite = count($matches)?key($matches):null;
- if ($value instanceof Sabre_VObject_Component || $value instanceof Sabre_VObject_Property) {
+ if ($value instanceof Component || $value instanceof Property) {
$value->parent = $this;
if (!is_null($overWrite)) {
$this->children[$overWrite] = $value;
@@ -314,7 +354,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$this->children[] = $value;
}
} elseif (is_scalar($value)) {
- $property = Sabre_VObject_Property::create($name,$value);
+ $property = Property::create($name,$value);
$property->parent = $this;
if (!is_null($overWrite)) {
$this->children[$overWrite] = $property;
@@ -322,7 +362,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$this->children[] = $property;
}
} else {
- throw new InvalidArgumentException('You must pass a Sabre_VObject_Component, Sabre_VObject_Property or scalar type');
+ throw new \InvalidArgumentException('You must pass a \\Sabre\\VObject\\Component, \\Sabre\\VObject\\Property or scalar type');
}
}