mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 13:39:22 +03:00
Remove Sabre\Xml unused functions
This commit is contained in:
parent
5cbaf80f75
commit
02623ab827
2 changed files with 0 additions and 159 deletions
|
|
@ -232,138 +232,3 @@ function valueObject(Reader $reader, string $className, string $namespace): obje
|
|||
|
||||
return $valueObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* This deserializer helps you deserialize xml structures that look like
|
||||
* this:.
|
||||
*
|
||||
* <collection>
|
||||
* <item>...</item>
|
||||
* <item>...</item>
|
||||
* <item>...</item>
|
||||
* </collection>
|
||||
*
|
||||
* Many XML documents use patterns like that, and this deserializer
|
||||
* allow you to get all the 'items' as an array.
|
||||
*
|
||||
* In that previous example, you would register the deserializer as such:
|
||||
*
|
||||
* $reader->elementMap['{}collection'] = function($reader) {
|
||||
* return repeatingElements($reader, '{}item');
|
||||
* }
|
||||
*
|
||||
* The repeatingElements deserializer simply returns everything as an array.
|
||||
*
|
||||
* $childElementName must either be a a clark-notation element name, or if no
|
||||
* namespace is used, the bare element name.
|
||||
*
|
||||
* @phpstan-return list<mixed>
|
||||
*/
|
||||
function repeatingElements(Reader $reader, string $childElementName): array
|
||||
{
|
||||
if ('{' !== $childElementName[0]) {
|
||||
$childElementName = '{}'.$childElementName;
|
||||
}
|
||||
$result = [];
|
||||
|
||||
foreach ($reader->parseGetElements() as $element) {
|
||||
if ($element['name'] === $childElementName) {
|
||||
$result[] = $element['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This deserializer helps you to deserialize structures which contain mixed content.
|
||||
*
|
||||
* <p>some text <extref>and a inline tag</extref>and even more text</p>
|
||||
*
|
||||
* The above example will return
|
||||
*
|
||||
* [
|
||||
* 'some text',
|
||||
* [
|
||||
* 'name' => '{}extref',
|
||||
* 'value' => 'and a inline tag',
|
||||
* 'attributes' => []
|
||||
* ],
|
||||
* 'and even more text'
|
||||
* ]
|
||||
*
|
||||
* In strict XML documents you wont find this kind of markup but in html this is a quite common pattern.
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
function mixedContent(Reader $reader): array
|
||||
{
|
||||
// If there's no children, we don't do anything.
|
||||
if ($reader->isEmptyElement) {
|
||||
$reader->next();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$previousDepth = $reader->depth;
|
||||
|
||||
$content = [];
|
||||
$reader->read();
|
||||
while (true) {
|
||||
if (Reader::ELEMENT == $reader->nodeType) {
|
||||
$content[] = $reader->parseCurrentElement();
|
||||
} elseif ($reader->depth >= $previousDepth && in_array($reader->nodeType, [Reader::TEXT, Reader::CDATA, Reader::WHITESPACE])) {
|
||||
$content[] = $reader->value;
|
||||
$reader->read();
|
||||
} elseif (Reader::END_ELEMENT == $reader->nodeType) {
|
||||
// Ensuring we are moving the cursor after the end element.
|
||||
$reader->read();
|
||||
break;
|
||||
} else {
|
||||
$reader->read();
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,30 +69,6 @@ function valueObject(Writer $writer, object $valueObject, string $namespace): vo
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This serializer helps you serialize xml structures that look like
|
||||
* this:.
|
||||
*
|
||||
* <collection>
|
||||
* <item>...</item>
|
||||
* <item>...</item>
|
||||
* <item>...</item>
|
||||
* </collection>
|
||||
*
|
||||
* In that previous example, this serializer just serializes the item element,
|
||||
* and this could be called like this:
|
||||
*
|
||||
* repeatingElements($writer, $items, '{}item');
|
||||
*
|
||||
* @param array<int,mixed> $items
|
||||
*/
|
||||
function repeatingElements(Writer $writer, array $items, string $childElementName): void
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
$writer->writeElement($childElementName, $item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is the 'default' serializer that is able to serialize most
|
||||
* things, and delegates to other serializers if needed.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue