aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/xml/lib/Deserializer
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-05-07 15:22:25 +0000
committerMario <mario@mariovavti.com>2020-05-07 15:22:25 +0000
commitdbfe748d274f6843fc91a3071df7be45c4ab5b00 (patch)
tree3b59194620f319b16a88dcc2aa5bacbea1c3d188 /vendor/sabre/xml/lib/Deserializer
parent4ee809bed6ea023ad9e2888eedd65e083d4c1e3e (diff)
downloadvolse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.tar.gz
volse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.tar.bz2
volse-hubzilla-dbfe748d274f6843fc91a3071df7be45c4ab5b00.zip
composer updates
Diffstat (limited to 'vendor/sabre/xml/lib/Deserializer')
-rw-r--r--vendor/sabre/xml/lib/Deserializer/functions.php43
1 files changed, 42 insertions, 1 deletions
diff --git a/vendor/sabre/xml/lib/Deserializer/functions.php b/vendor/sabre/xml/lib/Deserializer/functions.php
index 0eff4b7e0..c4f240970 100644
--- a/vendor/sabre/xml/lib/Deserializer/functions.php
+++ b/vendor/sabre/xml/lib/Deserializer/functions.php
@@ -173,7 +173,7 @@ function enum(Reader $reader, string $namespace = null): array
if (!is_null($namespace) && $namespace === $reader->namespaceURI) {
$values[] = $reader->localName;
} else {
- $values[] = $reader->getClark();
+ $values[] = (string) $reader->getClark();
}
} while ($reader->depth >= $currentDepth && $reader->next());
@@ -316,3 +316,44 @@ function mixedContent(Reader $reader): array
return $content;
}
+
+/**
+ * The functionCaller deserializer turns an xml element into whatever your callable return.
+ *
+ * You can use, e.g., a named constructor (factory method) to create an object using
+ * this function.
+ *
+ * @return mixed
+ */
+function functionCaller(Reader $reader, callable $func, string $namespace)
+{
+ if ($reader->isEmptyElement) {
+ $reader->next();
+
+ return null;
+ }
+
+ $funcArgs = [];
+ $func = is_string($func) && false !== strpos($func, '::') ? explode('::', $func) : $func;
+ $ref = is_array($func) ? new \ReflectionMethod($func[0], $func[1]) : new \ReflectionFunction($func);
+ foreach ($ref->getParameters() as $parameter) {
+ $funcArgs[$parameter->getName()] = null;
+ }
+
+ $reader->read();
+ do {
+ if (Reader::ELEMENT === $reader->nodeType && $reader->namespaceURI == $namespace) {
+ if (array_key_exists($reader->localName, $funcArgs)) {
+ $funcArgs[$reader->localName] = $reader->parseCurrentElement()['value'];
+ } else {
+ // Ignore property
+ $reader->next();
+ }
+ } else {
+ $reader->read();
+ }
+ } while (Reader::END_ELEMENT !== $reader->nodeType);
+ $reader->read();
+
+ return $func(...array_values($funcArgs));
+}