Skip to content

Commit 80deefa

Browse files
author
Mark Schmale
committed
bug #61021: add can to the accessor prefixes recognized by the AttributeLoader
The ObjectNormalizer already recognizes `canX` as an accessor and "generates" a property for that, the AttributeLoader does not, so #[Ignore] attributes on `canX` are ignored, the return value is encoded in the normalized data. We just add the `can` prefix ot the list of accepted accessor prefixes, so the AttributeLoader now also recognized these.
1 parent 01f0faf commit 80deefa

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Symfony/Component/Serializer/Mapping/Loader/AttributeLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
114114
continue; /* matches the BC behavior in `Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes` */
115115
}
116116

117-
$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
117+
$accessorOrMutator = preg_match('/^(get|is|has|set|can)(.+)$/i', $method->name, $matches);
118118
if ($accessorOrMutator && !ctype_lower($matches[2][0])) {
119119
$attributeName = lcfirst($matches[2]);
120120

src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/IgnoreDummy.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ public function getIgnored2()
2828
{
2929
return $this->ignored2;
3030
}
31+
32+
#[Ignore]
33+
public function getSomethingElse(): int
34+
{
35+
return 42;
36+
}
37+
38+
#[Ignore]
39+
public function canBeIgnored(): bool
40+
{
41+
return true;
42+
}
3143
}

src/Symfony/Component/Serializer/Tests/Mapping/Loader/AttributeLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public function testLoadIgnore()
153153
$attributesMetadata = $classMetadata->getAttributesMetadata();
154154
$this->assertTrue($attributesMetadata['ignored1']->isIgnored());
155155
$this->assertTrue($attributesMetadata['ignored2']->isIgnored());
156+
$this->assertTrue($attributesMetadata['somethingElse']->isIgnored());
157+
$this->assertTrue($attributesMetadata['beIgnored']->isIgnored());
156158
}
157159

158160
public function testLoadContextsPropertiesPromoted()

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