Skip to content

Commit 4411e73

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: [Dotenv] Documentation improvement [DI] Clarified deprecation for TypedReference in 4.4 [Validator] Add missing vietnamese translations add German translation add missing Messenger options to XML schema definition [Validator][ConstraintValidator] Update wrong PRETTY_DATE doc [DomCrawler][Form] Fix PHPDoc on get & offsetGet [ErrorHandler] fix parsing static return type on interface method annotation (fix #35836) prevent method calls on null values Return int if scale = 0
2 parents 94e385d + bc76d24 commit 4411e73

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Encoder/XmlEncoder.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Serializer\Encoder;
1313

14+
use Symfony\Component\Serializer\Exception\BadMethodCallException;
1415
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
1516
use Symfony\Component\Serializer\SerializerAwareInterface;
1617
use Symfony\Component\Serializer\SerializerAwareTrait;
@@ -368,7 +369,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
368369
$removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false;
369370
$encoderIgnoredNodeTypes = $this->context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
370371

371-
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
372+
if (\is_array($data) || ($data instanceof \Traversable && (null === $this->serializer || !$this->serializer->supportsNormalization($data, $this->format)))) {
372373
foreach ($data as $key => $data) {
373374
//Ah this is the magic @ attribute types.
374375
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
@@ -407,6 +408,10 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
407408
}
408409

409410
if (\is_object($data)) {
411+
if (null === $this->serializer) {
412+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
413+
}
414+
410415
$data = $this->serializer->normalize($data, $this->format, $this->context);
411416
if (null !== $data && !is_scalar($data)) {
412417
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
@@ -469,6 +474,10 @@ private function selectNodeType(\DOMNode $node, $val): bool
469474
} elseif ($val instanceof \Traversable) {
470475
$this->buildXml($node, $val);
471476
} elseif (\is_object($val)) {
477+
if (null === $this->serializer) {
478+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
479+
}
480+
472481
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
473482
} elseif (is_numeric($val)) {
474483
return $this->appendText($node, (string) $val);

Normalizer/ArrayDenormalizer.php

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function denormalize($data, string $type, string $format = null, array $c
6868
*/
6969
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
7070
{
71+
if (null === $this->serializer) {
72+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used.', __METHOD__));
73+
}
74+
7175
return '[]' === substr($type, -2)
7276
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
7377
}

0 commit comments

Comments
 (0)