Sabre/Xml v4.0.5

This commit is contained in:
the-djmaze 2024-08-27 15:27:44 +02:00
parent 9e3d6c6e23
commit 1ac4f05d91
6 changed files with 14 additions and 14 deletions

View file

@ -57,7 +57,7 @@ use Sabre\Xml\Reader;
* *
* @phpstan-return array<string, mixed> * @phpstan-return array<string, mixed>
*/ */
function keyValue(Reader $reader, string $namespace = null): array function keyValue(Reader $reader, ?string $namespace = null): array
{ {
// If there's no children, we don't do anything. // If there's no children, we don't do anything.
if ($reader->isEmptyElement) { if ($reader->isEmptyElement) {
@ -148,7 +148,7 @@ function keyValue(Reader $reader, string $namespace = null): array
* *
* @phpstan-return list<string> * @phpstan-return list<string>
*/ */
function enum(Reader $reader, string $namespace = null): array function enum(Reader $reader, ?string $namespace = null): array
{ {
// If there's no children, we don't do anything. // If there's no children, we don't do anything.
if ($reader->isEmptyElement) { if ($reader->isEmptyElement) {
@ -223,6 +223,9 @@ function valueObject(Reader $reader, string $className, string $namespace): obje
// Ignore property // Ignore property
$reader->next(); $reader->next();
} }
} elseif (Reader::ELEMENT === $reader->nodeType) {
// Skipping element from different namespace
$reader->next();
} else { } else {
if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) { if (Reader::END_ELEMENT !== $reader->nodeType && !$reader->read()) {
break; break;

View file

@ -31,7 +31,7 @@ class LibXMLException extends ParseException
* *
* @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; $this->errors = $errors;
parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException); parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException);

View file

@ -107,7 +107,7 @@ class Reader extends \XMLReader
* *
* @return array<int,array<string, mixed>> * @return array<int,array<string, mixed>>
*/ */
public function parseGetElements(array $elementMap = null): array public function parseGetElements(?array $elementMap = null): array
{ {
$result = $this->parseInnerTree($elementMap); $result = $this->parseInnerTree($elementMap);
if (!is_array($result)) { if (!is_array($result)) {
@ -132,7 +132,7 @@ class Reader extends \XMLReader
* *
* @return array<int,array<string, mixed>>|string|null * @return array<int,array<string, mixed>>|string|null
*/ */
public function parseInnerTree(array $elementMap = null) public function parseInnerTree(?array $elementMap = null)
{ {
$text = null; $text = null;
$elements = []; $elements = [];

View file

@ -107,7 +107,7 @@ class Service
* *
* @throws ParseException * @throws ParseException
*/ */
public function parse($input, string $contextUri = null, string &$rootElementName = null) public function parse($input, ?string $contextUri = null, ?string &$rootElementName = null)
{ {
if (is_resource($input)) { if (is_resource($input)) {
// Unfortunately the XMLReader doesn't support streams. When it // Unfortunately the XMLReader doesn't support streams. When it
@ -151,7 +151,7 @@ class Service
* *
* @throws ParseException * @throws ParseException
*/ */
public function expect($rootElementName, $input, string $contextUri = null) public function expect($rootElementName, $input, ?string $contextUri = null)
{ {
if (is_resource($input)) { if (is_resource($input)) {
// Unfortunately the XMLReader doesn't support streams. When it // Unfortunately the XMLReader doesn't support streams. When it
@ -200,7 +200,7 @@ class Service
* *
* @param string|array<int|string, mixed>|object|XmlSerializable $value * @param string|array<int|string, mixed>|object|XmlSerializable $value
*/ */
public function write(string $rootElementName, $value, string $contextUri = null): string public function write(string $rootElementName, $value, ?string $contextUri = null): string
{ {
$w = $this->getWriter(); $w = $this->getWriter();
$w->openMemory(); $w->openMemory();
@ -241,7 +241,6 @@ class Service
public function mapValueObject(string $elementName, string $className): void public function mapValueObject(string $elementName, string $className): void
{ {
list($namespace) = self::parseClarkNotation($elementName); list($namespace) = self::parseClarkNotation($elementName);
$namespace = $namespace ?? '';
require_once __DIR__ . '/Deserializer/functions.php'; require_once __DIR__ . '/Deserializer/functions.php';
$this->elementMap[$elementName] = function (Reader $reader) use ($className, $namespace) { $this->elementMap[$elementName] = function (Reader $reader) use ($className, $namespace) {
@ -265,7 +264,7 @@ class Service
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function writeValueObject(object $object, string $contextUri = null): string public function writeValueObject(object $object, ?string $contextUri = null): string
{ {
if (!isset($this->valueObjectMap[get_class($object)])) { if (!isset($this->valueObjectMap[get_class($object)])) {
throw new \InvalidArgumentException('"'.get_class($object).'" is not a registered value object class. Register your class with mapValueObject.'); throw new \InvalidArgumentException('"'.get_class($object).'" is not a registered value object class. Register your class with mapValueObject.');
@ -284,7 +283,7 @@ class Service
* *
* If the string was invalid, it will throw an InvalidArgumentException. * If the string was invalid, it will throw an InvalidArgumentException.
* *
* @return array{string|null, string} * @return array{string, string}
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */

View file

@ -16,5 +16,5 @@ class Version
/** /**
* Full version number. * Full version number.
*/ */
public const VERSION = '4.0.4'; public const VERSION = '4.0.5';
} }

View file

@ -125,7 +125,6 @@ class Writer extends \XMLWriter
if ('{' === $name[0]) { if ('{' === $name[0]) {
list($namespace, $localName) = list($namespace, $localName) =
Service::parseClarkNotation($name); Service::parseClarkNotation($name);
$namespace = $namespace ?? '';
if (array_key_exists($namespace, $this->namespaceMap)) { if (array_key_exists($namespace, $this->namespaceMap)) {
$result = $this->startElementNS( $result = $this->startElementNS(
@ -240,7 +239,6 @@ class Writer extends \XMLWriter
$localName $localName
) = Service::parseClarkNotation($name); ) = Service::parseClarkNotation($name);
$namespace = $namespace ?? '';
if (array_key_exists($namespace, $this->namespaceMap)) { if (array_key_exists($namespace, $this->namespaceMap)) {
// It's an attribute with a namespace we know // It's an attribute with a namespace we know
return $this->writeAttribute( return $this->writeAttribute(