Skip to content

Commit bc76d24

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [Validator] Add missing vietnamese translations add German translation [Validator][ConstraintValidator] Update wrong PRETTY_DATE doc [DomCrawler][Form] Fix PHPDoc on get & offsetGet prevent method calls on null values Return int if scale = 0
2 parents b19aa3e + f8b9983 commit bc76d24

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Encoder/XmlEncoder.php

Lines changed: 10 additions & 1 deletion
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;
@@ -413,7 +414,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
413414
$removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false;
414415
$encoderIgnoredNodeTypes = $this->context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
415416

416-
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
417+
if (\is_array($data) || ($data instanceof \Traversable && (null === $this->serializer || !$this->serializer->supportsNormalization($data, $this->format)))) {
417418
foreach ($data as $key => $data) {
418419
//Ah this is the magic @ attribute types.
419420
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
@@ -452,6 +453,10 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
452453
}
453454

454455
if (\is_object($data)) {
456+
if (null === $this->serializer) {
457+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
458+
}
459+
455460
$data = $this->serializer->normalize($data, $this->format, $this->context);
456461
if (null !== $data && !is_scalar($data)) {
457462
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
@@ -514,6 +519,10 @@ private function selectNodeType(\DOMNode $node, $val): bool
514519
} elseif ($val instanceof \Traversable) {
515520
$this->buildXml($node, $val);
516521
} elseif (\is_object($val)) {
522+
if (null === $this->serializer) {
523+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
524+
}
525+
517526
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
518527
} elseif (is_numeric($val)) {
519528
return $this->appendText($node, (string) $val);

Normalizer/ArrayDenormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function denormalize($data, $type, $format = null, array $context = [])
6868
*/
6969
public function supportsDenormalization($data, $type, $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)