Skip to content

Commit 709b257

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Serializer] Fix deserialization_path missing using contructor [HttpKernel] Fix logging deprecations to the "php" channel when channel "deprecation" is not defined fix detecting the server version with Doctrine DBAL 4 [Serializer] Fix constructor deserialization path [Serializer] Fix XML attributes not added on empty
2 parents 43a1fa1 + cd98a3f commit 709b257

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
param('debug.error_handler.throw_at'),
2828
param('kernel.debug'),
2929
param('kernel.debug'),
30-
service('logger')->nullOnInvalid(),
30+
null, // Deprecation logger if different from the one above
3131
])
3232
->tag('monolog.logger', ['channel' => 'php'])
3333

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Doctrine\DBAL\ParameterType;
2222
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
2323
use Doctrine\DBAL\Schema\Schema;
24+
use Doctrine\DBAL\ServerVersionProvider;
2425
use Doctrine\DBAL\Tools\DsnParser;
2526
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2627
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -388,6 +389,10 @@ private function getServerVersion(): string
388389
return $this->serverVersion;
389390
}
390391

392+
if ($this->conn instanceof ServerVersionProvider) {
393+
return $this->conn->getServerVersion();
394+
}
395+
391396
// The condition should be removed once support for DBAL <3.3 is dropped
392397
$conn = method_exists($this->conn, 'getNativeConnection') ? $this->conn->getNativeConnection() : $this->conn->getWrappedConnection();
393398
if ($conn instanceof ServerInfoAwareConnection) {

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

+21-12
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,22 @@ public function decode(string $data, string $format, array $context = []): mixed
135135
// todo: throw an exception if the root node name is not correctly configured (bc)
136136

137137
if ($rootNode->hasChildNodes()) {
138-
$xpath = new \DOMXPath($dom);
139-
$data = [];
140-
foreach ($xpath->query('namespace::*', $dom->documentElement) as $nsNode) {
141-
$data['@'.$nsNode->nodeName] = $nsNode->nodeValue;
138+
$data = $this->parseXml($rootNode, $context);
139+
if (\is_array($data)) {
140+
$data = $this->addXmlNamespaces($data, $rootNode, $dom);
142141
}
143142

144-
unset($data['@xmlns:xml']);
145-
146-
if (empty($data)) {
147-
return $this->parseXml($rootNode, $context);
148-
}
149-
150-
return array_merge($data, (array) $this->parseXml($rootNode, $context));
143+
return $data;
151144
}
152145

153146
if (!$rootNode->hasAttributes()) {
154147
return $rootNode->nodeValue;
155148
}
156149

157-
return array_merge($this->parseXmlAttributes($rootNode, $context), ['#' => $rootNode->nodeValue]);
150+
$data = array_merge($this->parseXmlAttributes($rootNode, $context), ['#' => $rootNode->nodeValue]);
151+
$data = $this->addXmlNamespaces($data, $rootNode, $dom);
152+
153+
return $data;
158154
}
159155

160156
public function supportsEncoding(string $format): bool
@@ -326,6 +322,19 @@ private function parseXmlValue(\DOMNode $node, array $context = []): array|strin
326322
return $value;
327323
}
328324

325+
private function addXmlNamespaces(array $data, \DOMNode $node, \DOMDocument $document): array
326+
{
327+
$xpath = new \DOMXPath($document);
328+
329+
foreach ($xpath->query('namespace::*', $node) as $nsNode) {
330+
$data['@'.$nsNode->nodeName] = $nsNode->nodeValue;
331+
}
332+
333+
unset($data['@xmlns:xml']);
334+
335+
return $data;
336+
}
337+
329338
/**
330339
* Parse the data and convert it to DOMElements.
331340
*

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,15 @@ protected function instantiateObject(array &$data, string $class, array &$contex
342342
$missingConstructorArguments = [];
343343
$params = [];
344344
$unsetKeys = [];
345+
$objectDeserializationPath = $context['deserialization_path'] ?? null;
346+
345347
foreach ($constructorParameters as $constructorParameter) {
346348
$paramName = $constructorParameter->name;
347349
$attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context);
348350
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName, $class, $format, $context) : $paramName;
349351

352+
$context['deserialization_path'] = $objectDeserializationPath ? $objectDeserializationPath.'.'.$paramName : $paramName;
353+
350354
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
351355
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
352356
if ($constructorParameter->isVariadic()) {
@@ -402,13 +406,15 @@ protected function instantiateObject(array &$data, string $class, array &$contex
402406
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
403407
$data,
404408
['unknown'],
405-
$context['deserialization_path'] ?? null,
409+
$objectDeserializationPath,
406410
true
407411
);
408412
$context['not_normalizable_value_exceptions'][] = $exception;
409413
}
410414
}
411415

416+
$context['deserialization_path'] = $objectDeserializationPath;
417+
412418
if ($missingConstructorArguments) {
413419
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
414420
}

src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,17 @@ public function testDecodeWithNamespace()
452452
$array = $this->getNamespacedArray();
453453

454454
$this->assertEquals($array, $this->encoder->decode($source, 'xml'));
455+
456+
$source = '<?xml version="1.0"?>'."\n".
457+
'<response xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" app:foo="bar">'.
458+
'</response>'."\n";
459+
460+
$this->assertEquals([
461+
'@xmlns' => 'http://www.w3.org/2005/Atom',
462+
'@xmlns:app' => 'http://www.w3.org/2007/app',
463+
'@app:foo' => 'bar',
464+
'#' => '',
465+
], $this->encoder->decode($source, 'xml'));
455466
}
456467

457468
public function testDecodeScalarWithAttribute()

0 commit comments

Comments
 (0)