Skip to content

Commit 4d3603d

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Fix CS Fix CS quote address names if they contain parentheses [FrameworkBundle] Fail gracefully when forms use disabled CSRF [Mime] Fix inline parts when added via attachPart() Fail gracefully when attempting to autowire composite types [VarDumper] Add a test case for nesting intersection and union types Fix #46592 - Ignore getter with required parameters [Serializer] Fix inconsistent behaviour of nullable objects in key/value arrays
2 parents a63ab4d + 9b7ee6f commit 4d3603d

10 files changed

+413
-4
lines changed

Mapping/Loader/AnnotationLoader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
100100
continue;
101101
}
102102

103+
$getAccessor = preg_match('/^(get|)(.+)$/i', $method->name);
104+
if ($getAccessor && 0 !== $method->getNumberOfRequiredParameters()) {
105+
continue; /* matches the BC behavior in `Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes` */
106+
}
107+
103108
$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
104109
if ($accessorOrMutator) {
105110
$attributeName = lcfirst($matches[2]);

Normalizer/AbstractObjectNormalizer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
351351

352352
$this->validateCallbackContext($context);
353353

354+
if (null === $data && isset($context['value_type']) && $context['value_type'] instanceof Type && $context['value_type']->isNullable()) {
355+
return null;
356+
}
357+
354358
$allowedAttributes = $this->getAllowedAttributes($type, $context, true);
355359
$normalizedData = $this->prepareForDenormalization($data);
356360
$extraAttributes = [];
@@ -521,6 +525,8 @@ private function validateAndDenormalize(array $types, string $currentClass, stri
521525
if (\count($collectionKeyType = $type->getCollectionKeyTypes()) > 0) {
522526
[$context['key_type']] = $collectionKeyType;
523527
}
528+
529+
$context['value_type'] = $collectionValueType;
524530
} elseif ($type->isCollection() && \count($collectionValueType = $type->getCollectionValueTypes()) > 0 && Type::BUILTIN_TYPE_ARRAY === $collectionValueType[0]->getBuiltinType()) {
525531
// get inner type for any nested array
526532
[$innerType] = $collectionValueType;

Tests/Fixtures/Annotations/Entity45016.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
64

75
use Symfony\Component\Serializer\Annotation\Ignore;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
4+
5+
use Symfony\Component\Serializer\Annotation\Ignore;
6+
7+
class IgnoreDummyAdditionalGetter
8+
{
9+
private $myValue;
10+
11+
/**
12+
* @Ignore()
13+
*/
14+
public function getMyValue()
15+
{
16+
return $this->myValue;
17+
}
18+
19+
public function getExtraValue(string $parameter)
20+
{
21+
return $parameter;
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
4+
5+
class IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations
6+
{
7+
private $myValue;
8+
9+
public function getMyValue()
10+
{
11+
return $this->myValue;
12+
}
13+
14+
public function getExtraValue(string $parameter)
15+
{
16+
return $parameter;
17+
}
18+
}

Tests/Fixtures/Attributes/Entity45016.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
64

75
use Symfony\Component\Serializer\Annotation\Ignore;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
4+
5+
use Symfony\Component\Serializer\Annotation\Ignore;
6+
7+
class IgnoreDummyAdditionalGetter
8+
{
9+
private $myValue;
10+
11+
#[Ignore]
12+
public function getIgnored2()
13+
{
14+
return $this->myValue;
15+
}
16+
17+
public function getExtraValue(string $parameter)
18+
{
19+
return $parameter;
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
4+
5+
class IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations
6+
{
7+
private $myValue;
8+
9+
public function getIgnored2()
10+
{
11+
return $this->myValue;
12+
}
13+
14+
public function getExtraValue(string $parameter)
15+
{
16+
return $parameter;
17+
}
18+
}

Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ public function testCanHandleUnrelatedIgnoredMethods()
150150
$loader->loadClassMetadata($metadata);
151151
}
152152

153+
public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()
154+
{
155+
$classMetadata = new ClassMetadata($this->getNamespace().'\IgnoreDummyAdditionalGetter');
156+
$this->getLoaderForContextMapping()->loadClassMetadata($classMetadata);
157+
158+
$attributes = $classMetadata->getAttributesMetadata();
159+
self::assertArrayNotHasKey('extraValue', $attributes);
160+
}
161+
162+
public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsNotUsed()
163+
{
164+
$classMetadata = new ClassMetadata($this->getNamespace().'\IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations');
165+
$this->getLoaderForContextMapping()->loadClassMetadata($classMetadata);
166+
167+
$attributes = $classMetadata->getAttributesMetadata();
168+
self::assertArrayNotHasKey('extraValue', $attributes);
169+
}
170+
153171
abstract protected function createLoader(): AnnotationLoader;
154172

155173
abstract protected function getNamespace(): string;

0 commit comments

Comments
 (0)