Skip to content

Commit fb1da0b

Browse files
Mark Schmalenicolas-grekas
authored andcommitted
[Serializer] add can to the accessor prefixes recognized by the AttributeLoader
1 parent 01f0faf commit fb1da0b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for `can*()` methods to `AttributeLoader`
8+
49
7.3
510
---
611

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public function getIgnored2()
2828
{
2929
return $this->ignored2;
3030
}
31+
32+
#[Ignore]
33+
public function canBeIgnored(): bool
34+
{
35+
return true;
36+
}
3137
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function testLoadIgnore()
153153
$attributesMetadata = $classMetadata->getAttributesMetadata();
154154
$this->assertTrue($attributesMetadata['ignored1']->isIgnored());
155155
$this->assertTrue($attributesMetadata['ignored2']->isIgnored());
156+
$this->assertTrue($attributesMetadata['beIgnored']->isIgnored());
156157
}
157158

158159
public function testLoadContextsPropertiesPromoted()

0 commit comments

Comments
 (0)