aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/lib/Component.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2019-04-25 11:24:09 +0200
committerMario <mario@mariovavti.com>2019-04-25 11:24:09 +0200
commitf1c07977809ce3221286d53e99f0d91145b1166f (patch)
tree4c067a3b701ea56f10070c386b26a30f93666eb0 /vendor/sabre/vobject/lib/Component.php
parent701167bc125700efb3e6ce759b85bcb4d36ee42e (diff)
downloadvolse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.tar.gz
volse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.tar.bz2
volse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.zip
Revert "update composer libs"
This reverts commit e779335d060b3a51d6a144d23af4097ae6801473
Diffstat (limited to 'vendor/sabre/vobject/lib/Component.php')
-rw-r--r--vendor/sabre/vobject/lib/Component.php236
1 files changed, 139 insertions, 97 deletions
diff --git a/vendor/sabre/vobject/lib/Component.php b/vendor/sabre/vobject/lib/Component.php
index a33b7d577..ac87a10ec 100644
--- a/vendor/sabre/vobject/lib/Component.php
+++ b/vendor/sabre/vobject/lib/Component.php
@@ -14,8 +14,8 @@ use Sabre\Xml;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Component extends Node
-{
+class Component extends Node {
+
/**
* Component name.
*
@@ -44,12 +44,14 @@ class Component extends Node
* ensure that this does not happen, set $defaults to false.
*
* @param Document $root
- * @param string $name such as VCALENDAR, VEVENT
- * @param array $children
- * @param bool $defaults
+ * @param string $name such as VCALENDAR, VEVENT.
+ * @param array $children
+ * @param bool $defaults
+ *
+ * @return void
*/
- public function __construct(Document $root, $name, array $children = [], $defaults = true)
- {
+ function __construct(Document $root, $name, array $children = [], $defaults = true) {
+
$this->name = strtoupper($name);
$this->root = $root;
@@ -82,11 +84,13 @@ class Component extends Node
// Component or Property
$this->add($child);
} else {
+
// Property key=>value
$this->add($k, $child);
}
}
}
+
}
/**
@@ -102,8 +106,8 @@ class Component extends Node
*
* @return Node
*/
- public function add()
- {
+ function add() {
+
$arguments = func_get_args();
if ($arguments[0] instanceof Node) {
@@ -112,10 +116,15 @@ class Component extends Node
}
$arguments[0]->parent = $this;
$newNode = $arguments[0];
+
} elseif (is_string($arguments[0])) {
+
$newNode = call_user_func_array([$this->root, 'create'], $arguments);
+
} else {
+
throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string');
+
}
$name = $newNode->name;
@@ -124,8 +133,8 @@ class Component extends Node
} else {
$this->children[$name] = [$newNode];
}
-
return $newNode;
+
}
/**
@@ -137,34 +146,36 @@ class Component extends Node
* exact item will be removed.
*
* @param string|Property|Component $item
+ * @return void
*/
- public function remove($item)
- {
+ function remove($item) {
+
if (is_string($item)) {
// If there's no dot in the name, it's an exact property name and
// we can just wipe out all those properties.
//
- if (false === strpos($item, '.')) {
+ if (strpos($item, '.') === false) {
unset($this->children[strtoupper($item)]);
-
return;
}
// If there was a dot, we need to ask select() to help us out and
// then we just call remove recursively.
foreach ($this->select($item) as $child) {
+
$this->remove($child);
+
}
} else {
foreach ($this->select($item->name) as $k => $child) {
if ($child === $item) {
unset($this->children[$item->name][$k]);
-
return;
}
}
}
throw new \InvalidArgumentException('The item you passed to remove() was not a child of this component');
+
}
/**
@@ -173,14 +184,14 @@ class Component extends Node
*
* @return array
*/
- public function children()
- {
+ function children() {
+
$result = [];
foreach ($this->children as $childGroup) {
$result = array_merge($result, $childGroup);
}
-
return $result;
+
}
/**
@@ -189,8 +200,8 @@ class Component extends Node
*
* @return array
*/
- public function getComponents()
- {
+ function getComponents() {
+
$result = [];
foreach ($this->children as $childGroup) {
@@ -200,8 +211,8 @@ class Component extends Node
}
}
}
-
return $result;
+
}
/**
@@ -215,21 +226,19 @@ class Component extends Node
* has not been assigned a group, specify ".EMAIL".
*
* @param string $name
- *
* @return array
*/
- public function select($name)
- {
+ function select($name) {
+
$group = null;
$name = strtoupper($name);
- if (false !== strpos($name, '.')) {
+ if (strpos($name, '.') !== false) {
list($group, $name) = explode('.', $name, 2);
}
- if ('' === $name) {
- $name = null;
- }
+ if ($name === '') $name = null;
if (!is_null($name)) {
+
$result = isset($this->children[$name]) ? $this->children[$name] : [];
if (is_null($group)) {
@@ -239,25 +248,32 @@ class Component extends Node
// more.
return array_filter(
$result,
- function ($child) use ($group) {
+ function($child) use ($group) {
+
return $child instanceof Property && strtoupper($child->group) === $group;
+
}
);
}
+
}
// If we got to this point, it means there was no 'name' specified for
// searching, implying that this is a group-only search.
$result = [];
foreach ($this->children as $childGroup) {
+
foreach ($childGroup as $child) {
+
if ($child instanceof Property && strtoupper($child->group) === $group) {
$result[] = $child;
}
+
}
- }
+ }
return $result;
+
}
/**
@@ -265,9 +281,9 @@ class Component extends Node
*
* @return string
*/
- public function serialize()
- {
- $str = 'BEGIN:'.$this->name."\r\n";
+ function serialize() {
+
+ $str = "BEGIN:" . $this->name . "\r\n";
/**
* Gives a component a 'score' for sorting purposes.
@@ -279,60 +295,60 @@ class Component extends Node
* space to accomodate elements. The $key is added to the $score to
* preserve the original relative order of elements.
*
- * @param int $key
+ * @param int $key
* @param array $array
*
* @return int
*/
- $sortScore = function ($key, $array) {
+ $sortScore = function($key, $array) {
+
if ($array[$key] instanceof Component) {
+
// We want to encode VTIMEZONE first, this is a personal
// preference.
- if ('VTIMEZONE' === $array[$key]->name) {
+ if ($array[$key]->name === 'VTIMEZONE') {
$score = 300000000;
-
return $score + $key;
} else {
$score = 400000000;
-
return $score + $key;
}
} else {
// Properties get encoded first
// VCARD version 4.0 wants the VERSION property to appear first
if ($array[$key] instanceof Property) {
- if ('VERSION' === $array[$key]->name) {
+ if ($array[$key]->name === 'VERSION') {
$score = 100000000;
-
return $score + $key;
} else {
// All other properties
$score = 200000000;
-
return $score + $key;
}
}
}
+
};
$children = $this->children();
$tmp = $children;
uksort(
$children,
- function ($a, $b) use ($sortScore, $tmp) {
+ function($a, $b) use ($sortScore, $tmp) {
+
$sA = $sortScore($a, $tmp);
$sB = $sortScore($b, $tmp);
return $sA - $sB;
+
}
);
- foreach ($children as $child) {
- $str .= $child->serialize();
- }
- $str .= 'END:'.$this->name."\r\n";
+ foreach ($children as $child) $str .= $child->serialize();
+ $str .= "END:" . $this->name . "\r\n";
return $str;
+
}
/**
@@ -341,8 +357,8 @@ class Component extends Node
*
* @return array
*/
- public function jsonSerialize()
- {
+ function jsonSerialize() {
+
$components = [];
$properties = [];
@@ -359,18 +375,21 @@ class Component extends Node
return [
strtolower($this->name),
$properties,
- $components,
+ $components
];
+
}
/**
* This method serializes the data into XML. This is used to create xCard or
* xCal documents.
*
- * @param Xml\Writer $writer XML writer
+ * @param Xml\Writer $writer XML writer.
+ *
+ * @return void
*/
- public function xmlSerialize(Xml\Writer $writer)
- {
+ function xmlSerialize(Xml\Writer $writer) {
+
$components = [];
$properties = [];
@@ -387,6 +406,7 @@ class Component extends Node
$writer->startElement(strtolower($this->name));
if (!empty($properties)) {
+
$writer->startElement('properties');
foreach ($properties as $property) {
@@ -394,9 +414,11 @@ class Component extends Node
}
$writer->endElement();
+
}
if (!empty($components)) {
+
$writer->startElement('components');
foreach ($components as $component) {
@@ -407,6 +429,7 @@ class Component extends Node
}
$writer->endElement();
+
}
/**
@@ -414,9 +437,10 @@ class Component extends Node
*
* @return array
*/
- protected function getDefaults()
- {
+ protected function getDefaults() {
+
return [];
+
}
/* Magic property accessors {{{ */
@@ -435,22 +459,24 @@ class Component extends Node
*
* @return Property
*/
- public function __get($name)
- {
- if ('children' === $name) {
+ function __get($name) {
+
+ if ($name === 'children') {
+
throw new \RuntimeException('Starting sabre/vobject 4.0 the children property is now protected. You should use the children() method instead');
+
}
$matches = $this->select($name);
- if (0 === count($matches)) {
+ if (count($matches) === 0) {
return;
} else {
$firstMatch = current($matches);
- /* @var $firstMatch Property */
+ /** @var $firstMatch Property */
$firstMatch->setIterator(new ElementList(array_values($matches)));
-
return $firstMatch;
}
+
}
/**
@@ -460,11 +486,11 @@ class Component extends Node
*
* @return bool
*/
- public function __isset($name)
- {
- $matches = $this->select($name);
+ function __isset($name) {
+ $matches = $this->select($name);
return count($matches) > 0;
+
}
/**
@@ -477,10 +503,12 @@ class Component extends Node
* a new item with the same name, always use the add() method.
*
* @param string $name
- * @param mixed $value
+ * @param mixed $value
+ *
+ * @return void
*/
- public function __set($name, $value)
- {
+ function __set($name, $value) {
+
$name = strtoupper($name);
$this->remove($name);
if ($value instanceof self || $value instanceof Property) {
@@ -495,10 +523,13 @@ class Component extends Node
* specified name.
*
* @param string $name
+ *
+ * @return void
*/
- public function __unset($name)
- {
+ function __unset($name) {
+
$this->remove($name);
+
}
/* }}} */
@@ -506,9 +537,11 @@ class Component extends Node
/**
* This method is automatically called when the object is cloned.
* Specifically, this will ensure all child elements are also cloned.
+ *
+ * @return void
*/
- public function __clone()
- {
+ function __clone() {
+
foreach ($this->children as $childName => $childGroup) {
foreach ($childGroup as $key => $child) {
$clonedChild = clone $child;
@@ -517,6 +550,7 @@ class Component extends Node
$this->children[$childName][$key] = $clonedChild;
}
}
+
}
/**
@@ -540,9 +574,10 @@ class Component extends Node
*
* @var array
*/
- public function getValidationRules()
- {
+ function getValidationRules() {
+
return [];
+
}
/**
@@ -569,8 +604,8 @@ class Component extends Node
*
* @return array
*/
- public function validate($options = 0)
- {
+ function validate($options = 0) {
+
$rules = $this->getValidationRules();
$defaults = $this->getDefaults();
@@ -583,48 +618,49 @@ class Component extends Node
if (!isset($propertyCounters[$name])) {
$propertyCounters[$name] = 1;
} else {
- ++$propertyCounters[$name];
+ $propertyCounters[$name]++;
}
$messages = array_merge($messages, $child->validate($options));
}
foreach ($rules as $propName => $rule) {
+
switch ($rule) {
- case '0':
+ case '0' :
if (isset($propertyCounters[$propName])) {
$messages[] = [
- 'level' => 3,
- 'message' => $propName.' MUST NOT appear in a '.$this->name.' component',
- 'node' => $this,
+ 'level' => 3,
+ 'message' => $propName . ' MUST NOT appear in a ' . $this->name . ' component',
+ 'node' => $this,
];
}
break;
- case '1':
- if (!isset($propertyCounters[$propName]) || 1 !== $propertyCounters[$propName]) {
+ case '1' :
+ if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] !== 1) {
$repaired = false;
if ($options & self::REPAIR && isset($defaults[$propName])) {
$this->add($propName, $defaults[$propName]);
$repaired = true;
}
$messages[] = [
- 'level' => $repaired ? 1 : 3,
- 'message' => $propName.' MUST appear exactly once in a '.$this->name.' component',
- 'node' => $this,
+ 'level' => $repaired ? 1 : 3,
+ 'message' => $propName . ' MUST appear exactly once in a ' . $this->name . ' component',
+ 'node' => $this,
];
}
break;
- case '+':
+ case '+' :
if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] < 1) {
$messages[] = [
- 'level' => 3,
- 'message' => $propName.' MUST appear at least once in a '.$this->name.' component',
- 'node' => $this,
+ 'level' => 3,
+ 'message' => $propName . ' MUST appear at least once in a ' . $this->name . ' component',
+ 'node' => $this,
];
}
break;
- case '*':
+ case '*' :
break;
- case '?':
+ case '?' :
if (isset($propertyCounters[$propName]) && $propertyCounters[$propName] > 1) {
$level = 3;
@@ -633,7 +669,7 @@ class Component extends Node
if ($options & self::REPAIR) {
$properties = array_unique($this->select($propName), SORT_REGULAR);
- if (1 === count($properties)) {
+ if (count($properties) === 1) {
$this->remove($propName);
$this->add($properties[0]);
@@ -642,16 +678,18 @@ class Component extends Node
}
$messages[] = [
- 'level' => $level,
- 'message' => $propName.' MUST NOT appear more than once in a '.$this->name.' component',
- 'node' => $this,
+ 'level' => $level,
+ 'message' => $propName . ' MUST NOT appear more than once in a ' . $this->name . ' component',
+ 'node' => $this,
];
}
break;
+
}
- }
+ }
return $messages;
+
}
/**
@@ -659,9 +697,11 @@ class Component extends Node
*
* It's intended to remove all circular references, so PHP can easily clean
* it up.
+ *
+ * @return void
*/
- public function destroy()
- {
+ function destroy() {
+
parent::destroy();
foreach ($this->children as $childGroup) {
foreach ($childGroup as $child) {
@@ -669,5 +709,7 @@ class Component extends Node
}
}
$this->children = [];
+
}
+
}