Skip to content

Commit 534369a

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [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 cd20971 + 7ace12d commit 534369a

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
@@ -359,12 +359,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
359359
$resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
360360

361361
foreach ($normalizedData as $attribute => $value) {
362-
$attributeContext = $this->getAttributeDenormalizationContext($resolvedClass, $attribute, $context);
363-
364362
if ($this->nameConverter) {
365-
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $attributeContext);
363+
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $context);
366364
}
367365

366+
$attributeContext = $this->getAttributeDenormalizationContext($resolvedClass, $attribute, $context);
367+
368368
if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($resolvedClass, $attribute, $format, $context)) {
369369
if (!($context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES])) {
370370
$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;
@@ -70,6 +71,17 @@ public function testContextMetadataContextDenormalize()
7071
]);
7172
self::assertEquals('2011-07-28', $dummy->date->format('Y-m-d'), 'a specific denormalization context is used for this group');
7273
}
74+
75+
public function testContextDenormalizeWithNameConverter()
76+
{
77+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
78+
$normalizer = new ObjectNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter(), null, new PhpDocExtractor());
79+
new Serializer([new DateTimeNormalizer(), $normalizer]);
80+
81+
/** @var ContextMetadataNamingDummy $dummy */
82+
$dummy = $normalizer->denormalize(['created_at' => '28/07/2011'], ContextMetadataNamingDummy::class);
83+
self::assertEquals('2011-07-28', $dummy->createdAt->format('Y-m-d'));
84+
}
7385
}
7486

7587
class ContextMetadataDummy
@@ -90,3 +102,13 @@ class ContextMetadataDummy
90102
*/
91103
public $date;
92104
}
105+
106+
class ContextMetadataNamingDummy
107+
{
108+
/**
109+
* @var \DateTime
110+
*
111+
* @Context({ DateTimeNormalizer::FORMAT_KEY = "d/m/Y" })
112+
*/
113+
public $createdAt;
114+
}

0 commit comments

Comments
 (0)