mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +03:00
Sabre/Xml 4.0.4 for #1311
This commit is contained in:
parent
70a2ebb671
commit
c8baabf8d9
15 changed files with 49 additions and 49 deletions
|
|
@ -63,7 +63,7 @@ trait ContextStackTrait
|
|||
* The writer may use this if you attempt to serialize an object with a
|
||||
* class that does not implement XmlSerializable.
|
||||
*
|
||||
* Instead it will look at this classmap to see if there is a custom
|
||||
* Instead, it will look at this classmap to see if there is a custom
|
||||
* serializer here. This is useful if you don't want your value objects
|
||||
* to be responsible for serializing themselves.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ function keyValue(Reader $reader, string $namespace = null): array
|
|||
* ];
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @phpstan-return list<string>
|
||||
*/
|
||||
function enum(Reader $reader, string $namespace = null): array
|
||||
|
|
@ -186,7 +187,7 @@ function enum(Reader $reader, string $namespace = null): array
|
|||
}
|
||||
|
||||
/**
|
||||
* The valueObject deserializer turns an xml element into a PHP object of
|
||||
* The valueObject deserializer turns an XML element into a PHP object of
|
||||
* a specific class.
|
||||
*
|
||||
* This is primarily used by the mapValueObject function from the Service
|
||||
|
|
@ -195,6 +196,7 @@ function enum(Reader $reader, string $namespace = null): array
|
|||
* @template C of object
|
||||
*
|
||||
* @param class-string<C> $className
|
||||
*
|
||||
* @phpstan-return C
|
||||
*/
|
||||
function valueObject(Reader $reader, string $className, string $namespace): object
|
||||
|
|
@ -222,7 +224,7 @@ function valueObject(Reader $reader, string $className, string $namespace): obje
|
|||
$reader->next();
|
||||
}
|
||||
} else {
|
||||
if (!$reader->read()) {
|
||||
if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,14 @@ use Sabre\Xml;
|
|||
class Base implements Xml\Element
|
||||
{
|
||||
/**
|
||||
* PHP value to serialize.
|
||||
*
|
||||
* @var mixed
|
||||
* @var mixed PHP value to serialize
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $value PHP value to serialize
|
||||
*/
|
||||
public function __construct($value = null)
|
||||
{
|
||||
|
|
@ -75,7 +73,7 @@ class Base implements Xml\Element
|
|||
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
|
||||
* the next element.
|
||||
*
|
||||
* @return mixed
|
||||
* @return array<int,array<string, mixed>>|string|null
|
||||
*/
|
||||
public static function xmlDeserialize(Xml\Reader $reader)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Elements implements Xml\Element
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function xmlDeserialize(Xml\Reader $reader): array
|
||||
public static function xmlDeserialize(Xml\Reader $reader)
|
||||
{
|
||||
require_once __DIR__ . '/../Deserializer/functions.php';
|
||||
return Deserializer\enum($reader);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class KeyValue implements Xml\Element
|
|||
*/
|
||||
public function xmlSerialize(Xml\Writer $writer): void
|
||||
{
|
||||
require_once __DIR__ . '/Serializer/functions.php';
|
||||
$writer->write($this->value);
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ class KeyValue implements Xml\Element
|
|||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function xmlDeserialize(Xml\Reader $reader): array
|
||||
public static function xmlDeserialize(Xml\Reader $reader)
|
||||
{
|
||||
require_once __DIR__ . '/../Deserializer/functions.php';
|
||||
return Deserializer\keyValue($reader);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sabre\Xml\Element;
|
||||
|
||||
use function Sabre\Uri\resolve;
|
||||
|
||||
use Sabre\Xml;
|
||||
|
||||
use function Sabre\Uri\resolve;
|
||||
|
||||
/**
|
||||
* Uri element.
|
||||
*
|
||||
|
|
@ -59,7 +59,7 @@ class Uri implements Xml\Element
|
|||
{
|
||||
$writer->text(
|
||||
resolve(
|
||||
$writer->contextUri,
|
||||
$writer->contextUri ?? '',
|
||||
$this->value
|
||||
)
|
||||
);
|
||||
|
|
@ -83,7 +83,7 @@ class Uri implements Xml\Element
|
|||
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
|
||||
* the next element.
|
||||
*/
|
||||
public static function xmlDeserialize(Xml\Reader $reader): Uri
|
||||
public static function xmlDeserialize(Xml\Reader $reader)
|
||||
{
|
||||
return new self(
|
||||
resolve(
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ XML;
|
|||
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
|
||||
* the next element.
|
||||
*/
|
||||
public static function xmlDeserialize(Reader $reader): XmlFragment
|
||||
public static function xmlDeserialize(Reader $reader)
|
||||
{
|
||||
$result = new self($reader->readInnerXml());
|
||||
$reader->next();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace Sabre\Xml;
|
||||
|
||||
use LibXMLError;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* This exception is thrown when the Reader runs into a parsing error.
|
||||
|
|
@ -30,9 +29,9 @@ class LibXMLException extends ParseException
|
|||
*
|
||||
* You should pass a list of LibXMLError objects in its constructor.
|
||||
*
|
||||
* @param LibXMLError[] $errors
|
||||
* @param \LibXMLError[] $errors
|
||||
*/
|
||||
public function __construct(array $errors, int $code = 0, Throwable $previousException = null)
|
||||
public function __construct(array $errors, int $code = 0, \Throwable $previousException = null)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException);
|
||||
|
|
@ -41,7 +40,7 @@ class LibXMLException extends ParseException
|
|||
/**
|
||||
* Returns the LibXML errors.
|
||||
*
|
||||
* @return LibXMLError[]
|
||||
* @return \LibXMLError[]
|
||||
*/
|
||||
public function getErrors(): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sabre\Xml;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* This is a base exception for any exception related to parsing xml files.
|
||||
*
|
||||
|
|
@ -13,6 +11,6 @@ use Exception;
|
|||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class ParseException extends Exception
|
||||
class ParseException extends \Exception
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use XMLReader;
|
|||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Reader extends XMLReader
|
||||
class Reader extends \XMLReader
|
||||
{
|
||||
use ContextStackTrait;
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class Reader extends XMLReader
|
|||
*
|
||||
* @param array<string, mixed>|null $elementMap
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
* @return array<int,array<string, mixed>>
|
||||
*/
|
||||
public function parseGetElements(array $elementMap = null): array
|
||||
{
|
||||
|
|
@ -130,7 +130,7 @@ class Reader extends XMLReader
|
|||
*
|
||||
* @param array<string, mixed>|null $elementMap
|
||||
*
|
||||
* @return array<string, mixed>|string|null
|
||||
* @return array<int,array<string, mixed>>|string|null
|
||||
*/
|
||||
public function parseInnerTree(array $elementMap = null)
|
||||
{
|
||||
|
|
@ -211,7 +211,7 @@ class Reader extends XMLReader
|
|||
$previousDepth = $this->depth;
|
||||
|
||||
while ($this->read() && $this->depth != $previousDepth) {
|
||||
if (in_array($this->nodeType, [XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE])) {
|
||||
if (in_array($this->nodeType, [\XMLReader::TEXT, \XMLReader::CDATA, \XMLReader::WHITESPACE])) {
|
||||
$result .= $this->value;
|
||||
}
|
||||
}
|
||||
|
|
@ -298,14 +298,14 @@ class Reader extends XMLReader
|
|||
}
|
||||
|
||||
$deserializer = $this->elementMap[$name];
|
||||
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
|
||||
return [$deserializer, 'xmlDeserialize'];
|
||||
}
|
||||
|
||||
if (is_callable($deserializer)) {
|
||||
return $deserializer;
|
||||
}
|
||||
|
||||
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
|
||||
return [$deserializer, 'xmlDeserialize'];
|
||||
}
|
||||
|
||||
$type = gettype($deserializer);
|
||||
if (is_string($deserializer)) {
|
||||
$type .= ' ('.$deserializer.')';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sabre\Xml\Serializer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Sabre\Xml\Writer;
|
||||
use Sabre\Xml\XmlSerializable;
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ function enum(Writer $writer, array $values): void
|
|||
/**
|
||||
* The valueObject serializer turns a simple PHP object into a classname.
|
||||
*
|
||||
* Every public property will be encoded as an xml element with the same
|
||||
* Every public property will be encoded as an XML element with the same
|
||||
* name, in the XML namespace as specified.
|
||||
*
|
||||
* Values that are set to null or an empty array are not serialized. To
|
||||
|
|
@ -173,12 +172,12 @@ function standardSerializer(Writer $writer, $value): void
|
|||
$writer->write($item);
|
||||
$writer->endElement();
|
||||
} else {
|
||||
throw new InvalidArgumentException('The writer does not know how to serialize arrays with keys of type: '.gettype($name));
|
||||
throw new \InvalidArgumentException('The writer does not know how to serialize arrays with keys of type: '.gettype($name));
|
||||
}
|
||||
}
|
||||
} elseif (is_object($value)) {
|
||||
throw new InvalidArgumentException('The writer cannot serialize objects of class: '.get_class($value));
|
||||
throw new \InvalidArgumentException('The writer cannot serialize objects of class: '.get_class($value));
|
||||
} elseif (!is_null($value)) {
|
||||
throw new InvalidArgumentException('The writer cannot serialize values of type: '.gettype($value));
|
||||
throw new \InvalidArgumentException('The writer cannot serialize values of type: '.gettype($value));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class Service
|
|||
* The writer may use this if you attempt to serialize an object with a
|
||||
* class that does not implement XmlSerializable.
|
||||
*
|
||||
* Instead it will look at this classmap to see if there is a custom
|
||||
* Instead, it will look at this classmap to see if there is a custom
|
||||
* serializer here. This is useful if you don't want your value objects
|
||||
* to be responsible for serializing themselves.
|
||||
*
|
||||
|
|
@ -103,9 +103,9 @@ class Service
|
|||
*
|
||||
* @param string|resource $input
|
||||
*
|
||||
* @throws ParseException
|
||||
*
|
||||
* @return array<string, mixed>|object|string
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
public function parse($input, string $contextUri = null, string &$rootElementName = null)
|
||||
{
|
||||
|
|
@ -147,9 +147,9 @@ class Service
|
|||
* @param string|string[] $rootElementName
|
||||
* @param string|resource $input
|
||||
*
|
||||
* @throws ParseException
|
||||
*
|
||||
* @return array<string, mixed>|object|string
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
public function expect($rootElementName, $input, string $contextUri = null)
|
||||
{
|
||||
|
|
@ -198,7 +198,7 @@ class Service
|
|||
* This allows an implementor to easily create URI's relative to the root
|
||||
* of the domain.
|
||||
*
|
||||
* @param string|array<string, mixed>|object|XmlSerializable $value
|
||||
* @param string|array<int|string, mixed>|object|XmlSerializable $value
|
||||
*/
|
||||
public function write(string $rootElementName, $value, string $contextUri = null): string
|
||||
{
|
||||
|
|
@ -241,6 +241,7 @@ class Service
|
|||
public function mapValueObject(string $elementName, string $className): void
|
||||
{
|
||||
list($namespace) = self::parseClarkNotation($elementName);
|
||||
$namespace = $namespace ?? '';
|
||||
|
||||
require_once __DIR__ . '/Deserializer/functions.php';
|
||||
$this->elementMap[$elementName] = function (Reader $reader) use ($className, $namespace) {
|
||||
|
|
@ -262,7 +263,7 @@ class Service
|
|||
* The ValueObject must have been previously registered using
|
||||
* mapValueObject().
|
||||
*
|
||||
*@throws \InvalidArgumentException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function writeValueObject(object $object, string $contextUri = null): string
|
||||
{
|
||||
|
|
@ -283,9 +284,9 @@ class Service
|
|||
*
|
||||
* If the string was invalid, it will throw an InvalidArgumentException.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return array{string|null, string}
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function parseClarkNotation(string $str): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@ class Version
|
|||
/**
|
||||
* Full version number.
|
||||
*/
|
||||
public const VERSION = '3.0.0';
|
||||
public const VERSION = '4.0.4';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use XMLWriter;
|
|||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Writer extends XMLWriter
|
||||
class Writer extends \XMLWriter
|
||||
{
|
||||
use ContextStackTrait;
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ class Writer extends XMLWriter
|
|||
* ]
|
||||
* ]
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $value PHP value to be written
|
||||
*/
|
||||
public function write($value): void
|
||||
{
|
||||
|
|
@ -125,6 +125,7 @@ class Writer extends XMLWriter
|
|||
if ('{' === $name[0]) {
|
||||
list($namespace, $localName) =
|
||||
Service::parseClarkNotation($name);
|
||||
$namespace = $namespace ?? '';
|
||||
|
||||
if (array_key_exists($namespace, $this->namespaceMap)) {
|
||||
$result = $this->startElementNS(
|
||||
|
|
@ -135,7 +136,7 @@ class Writer extends XMLWriter
|
|||
} else {
|
||||
// An empty namespace means it's the global namespace. This is
|
||||
// allowed, but it mustn't get a prefix.
|
||||
if ('' === $namespace || null === $namespace) {
|
||||
if ('' === $namespace) {
|
||||
$result = $this->startElement($localName);
|
||||
$this->writeAttribute('xmlns', '');
|
||||
} else {
|
||||
|
|
@ -239,6 +240,7 @@ class Writer extends XMLWriter
|
|||
$localName
|
||||
) = Service::parseClarkNotation($name);
|
||||
|
||||
$namespace = $namespace ?? '';
|
||||
if (array_key_exists($namespace, $this->namespaceMap)) {
|
||||
// It's an attribute with a namespace we know
|
||||
return $this->writeAttribute(
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ interface XmlDeserializable
|
|||
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
|
||||
* the next element.
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed see comments above
|
||||
*/
|
||||
public static function xmlDeserialize(Reader $reader);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue