Skip to content

Commit ab42c55

Browse files
committed
[Serializer] GetSetMethodNormalize: fix BC break with Ignore attribute
1 parent 2e73037 commit ab42c55

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Serializer\Normalizer;
1313

14+
use Symfony\Component\Serializer\Annotation\Ignore as LegacyIgnore;
1415
use Symfony\Component\Serializer\Attribute\Ignore;
1516

1617
/**
@@ -97,7 +98,7 @@ private function supports(string $class): bool
9798
private function isGetMethod(\ReflectionMethod $method): bool
9899
{
99100
return !$method->isStatic()
100-
&& !$method->getAttributes(Ignore::class)
101+
&& !($method->getAttributes(Ignore::class) || $method->getAttributes(LegacyIgnore::class))
101102
&& !$method->getNumberOfRequiredParameters()
102103
&& ((2 < ($methodLength = \strlen($method->name)) && str_starts_with($method->name, 'is'))
103104
|| (3 < $methodLength && (str_starts_with($method->name, 'has') || str_starts_with($method->name, 'get')))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
13+
14+
use Symfony\Component\Serializer\Annotation\Ignore;
15+
16+
class ClassWithIgnoreAnnotation
17+
{
18+
public string $foo;
19+
20+
#[Ignore]
21+
public function isSomeIgnoredMethod(): bool
22+
{
23+
return true;
24+
}
25+
}

src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
3131
use Symfony\Component\Serializer\Serializer;
3232
use Symfony\Component\Serializer\SerializerInterface;
33+
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAnnotation;
3334
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAttribute;
3435
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\GroupDummy;
3536
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
@@ -427,9 +428,22 @@ public function testNoStaticGetSetSupport()
427428
$this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
428429
}
429430

430-
public function testNotIgnoredMethodSupport()
431+
/**
432+
* @param class-string $class
433+
*
434+
* @dataProvider provideNotIgnoredMethodSupport
435+
*/
436+
public function testNotIgnoredMethodSupport(string $class)
431437
{
432-
$this->assertFalse($this->normalizer->supportsNormalization(new ClassWithIgnoreAttribute()));
438+
$this->assertFalse($this->normalizer->supportsNormalization(new $class()));
439+
}
440+
441+
public static function provideNotIgnoredMethodSupport(): iterable
442+
{
443+
return [
444+
[ClassWithIgnoreAttribute::class],
445+
[ClassWithIgnoreAnnotation::class],
446+
];
433447
}
434448

435449
public function testPrivateSetter()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy