Skip to content

Commit 96a4db9

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [Console] Prevent PHP 8.1 str_replace deprec on null Improve DE translations for Form/Validator [Serializer] Fix ignore attribute in Xml files [Console] Escape % in command name & description from getDefault*() [WebProfilerBundle] Fix dark theme selected line highlight color & reuse css vars [Mime] Check that the path is a file in the DataPart::fromPath [Cache] do not pass null to strlen() [Mailer] Sort transports alphabetically [Security] Fix some phpdoc [Serializer] Get attributeContext after converting name
2 parents 72acdf1 + 534369a commit 96a4db9

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

Mapping/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
7272
}
7373

7474
if (isset($attribute['ignore'])) {
75-
$attributeMetadata->setIgnore((bool) $attribute['ignore']);
75+
$attributeMetadata->setIgnore(XmlUtils::phpize($attribute['ignore']));
7676
}
7777

7878
foreach ($attribute->context as $node) {

Normalizer/AbstractObjectNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
364364
$resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
365365

366366
foreach ($normalizedData as $attribute => $value) {
367-
$attributeContext = $this->getAttributeDenormalizationContext($resolvedClass, $attribute, $context);
368-
369367
if ($this->nameConverter) {
370-
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $attributeContext);
368+
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $context);
371369
}
372370

371+
$attributeContext = $this->getAttributeDenormalizationContext($resolvedClass, $attribute, $context);
372+
373373
if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($resolvedClass, $attribute, $format, $context)) {
374374
if (!($context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES])) {
375375
$extraAttributes[] = $attribute;

Tests/Fixtures/serialization.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<class name="Symfony\Component\Serializer\Tests\Fixtures\Annotations\IgnoreDummy">
3838
<attribute name="ignored1" ignore="true" />
3939
<attribute name="ignored2" ignore="true" />
40+
<attribute name="notIgnored" ignore="false" />
4041
</class>
4142

4243
<class name="Symfony\Component\Serializer\Tests\Fixtures\Annotations\ContextDummyParent">

Tests/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function testLoadIgnore()
107107
$attributesMetadata = $classMetadata->getAttributesMetadata();
108108
$this->assertTrue($attributesMetadata['ignored1']->isIgnored());
109109
$this->assertTrue($attributesMetadata['ignored2']->isIgnored());
110+
$this->assertFalse($attributesMetadata['notIgnored']->isIgnored());
110111
}
111112

112113
protected function getLoaderForContextMapping(): LoaderInterface

Tests/Normalizer/Features/ContextMetadataTestTrait.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Serializer\Annotation\Groups;
1818
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1919
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
20+
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
2021
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
2122
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
2223
use Symfony\Component\Serializer\Serializer;
@@ -84,6 +85,17 @@ public function contextMetadataDummyProvider()
8485
[ContextChildMetadataDummy::class],
8586
];
8687
}
88+
89+
public function testContextDenormalizeWithNameConverter()
90+
{
91+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
92+
$normalizer = new ObjectNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter(), null, new PhpDocExtractor());
93+
new Serializer([new DateTimeNormalizer(), $normalizer]);
94+
95+
/** @var ContextMetadataNamingDummy $dummy */
96+
$dummy = $normalizer->denormalize(['created_at' => '28/07/2011'], ContextMetadataNamingDummy::class);
97+
self::assertEquals('2011-07-28', $dummy->createdAt->format('Y-m-d'));
98+
}
8799
}
88100

89101
class ContextMetadataDummy
@@ -123,3 +135,13 @@ class ContextChildMetadataDummy
123135
*/
124136
public $date;
125137
}
138+
139+
class ContextMetadataNamingDummy
140+
{
141+
/**
142+
* @var \DateTime
143+
*
144+
* @Context({ DateTimeNormalizer::FORMAT_KEY = "d/m/Y" })
145+
*/
146+
public $createdAt;
147+
}

0 commit comments

Comments
 (0)