Skip to content

Commit c2cb583

Browse files
minor symfony#58585 Rename annotations to attributes in AttributeLoader (alamirault)
This PR was merged into the 7.2 branch. Discussion ---------- Rename annotations to attributes in `AttributeLoader` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Annotations are not supported anymore in AttributeLoader, so we can rename some variables Commits ------- 9ab0752 [Serializer] Rename annotations to attributes in AttributeLoader
2 parents a86878f + 9ab0752 commit c2cb583

File tree

11 files changed

+49
-49
lines changed

11 files changed

+49
-49
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
5353
$className = $reflectionClass->name;
5454
$loaded = false;
5555
$classGroups = [];
56-
$classContextAnnotation = null;
56+
$classContextAttribute = null;
5757

5858
$attributesMetadata = $classMetadata->getAttributesMetadata();
5959

60-
foreach ($this->loadAttributes($reflectionClass) as $annotation) {
60+
foreach ($this->loadAttributes($reflectionClass) as $attribute) {
6161
match (true) {
62-
$annotation instanceof DiscriminatorMap => $classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping($annotation->getTypeProperty(), $annotation->getMapping())),
63-
$annotation instanceof Groups => $classGroups = $annotation->getGroups(),
64-
$annotation instanceof Context => $classContextAnnotation = $annotation,
62+
$attribute instanceof DiscriminatorMap => $classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping($attribute->getTypeProperty(), $attribute->getMapping())),
63+
$attribute instanceof Groups => $classGroups = $attribute->getGroups(),
64+
$attribute instanceof Context => $classContextAttribute = $attribute,
6565
default => null,
6666
};
6767
}
@@ -74,31 +74,31 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
7474

7575
$attributeMetadata = $attributesMetadata[$property->name];
7676
if ($property->getDeclaringClass()->name === $className) {
77-
if ($classContextAnnotation) {
78-
$this->setAttributeContextsForGroups($classContextAnnotation, $attributeMetadata);
77+
if ($classContextAttribute) {
78+
$this->setAttributeContextsForGroups($classContextAttribute, $attributeMetadata);
7979
}
8080

8181
foreach ($classGroups as $group) {
8282
$attributeMetadata->addGroup($group);
8383
}
8484

85-
foreach ($this->loadAttributes($property) as $annotation) {
85+
foreach ($this->loadAttributes($property) as $attribute) {
8686
$loaded = true;
8787

88-
if ($annotation instanceof Groups) {
89-
foreach ($annotation->getGroups() as $group) {
88+
if ($attribute instanceof Groups) {
89+
foreach ($attribute->getGroups() as $group) {
9090
$attributeMetadata->addGroup($group);
9191
}
9292

9393
continue;
9494
}
9595

9696
match (true) {
97-
$annotation instanceof MaxDepth => $attributeMetadata->setMaxDepth($annotation->getMaxDepth()),
98-
$annotation instanceof SerializedName => $attributeMetadata->setSerializedName($annotation->getSerializedName()),
99-
$annotation instanceof SerializedPath => $attributeMetadata->setSerializedPath($annotation->getSerializedPath()),
100-
$annotation instanceof Ignore => $attributeMetadata->setIgnore(true),
101-
$annotation instanceof Context => $this->setAttributeContextsForGroups($annotation, $attributeMetadata),
97+
$attribute instanceof MaxDepth => $attributeMetadata->setMaxDepth($attribute->getMaxDepth()),
98+
$attribute instanceof SerializedName => $attributeMetadata->setSerializedName($attribute->getSerializedName()),
99+
$attribute instanceof SerializedPath => $attributeMetadata->setSerializedPath($attribute->getSerializedPath()),
100+
$attribute instanceof Ignore => $attributeMetadata->setIgnore(true),
101+
$attribute instanceof Context => $this->setAttributeContextsForGroups($attribute, $attributeMetadata),
102102
default => null,
103103
};
104104
}
@@ -126,43 +126,43 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
126126
}
127127
}
128128

129-
foreach ($this->loadAttributes($method) as $annotation) {
130-
if ($annotation instanceof Groups) {
129+
foreach ($this->loadAttributes($method) as $attribute) {
130+
if ($attribute instanceof Groups) {
131131
if (!$accessorOrMutator) {
132132
throw new MappingException(\sprintf('Groups on "%s::%s()" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
133133
}
134134

135-
foreach ($annotation->getGroups() as $group) {
135+
foreach ($attribute->getGroups() as $group) {
136136
$attributeMetadata->addGroup($group);
137137
}
138-
} elseif ($annotation instanceof MaxDepth) {
138+
} elseif ($attribute instanceof MaxDepth) {
139139
if (!$accessorOrMutator) {
140140
throw new MappingException(\sprintf('MaxDepth on "%s::%s()" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
141141
}
142142

143-
$attributeMetadata->setMaxDepth($annotation->getMaxDepth());
144-
} elseif ($annotation instanceof SerializedName) {
143+
$attributeMetadata->setMaxDepth($attribute->getMaxDepth());
144+
} elseif ($attribute instanceof SerializedName) {
145145
if (!$accessorOrMutator) {
146146
throw new MappingException(\sprintf('SerializedName on "%s::%s()" cannot be added. SerializedName can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
147147
}
148148

149-
$attributeMetadata->setSerializedName($annotation->getSerializedName());
150-
} elseif ($annotation instanceof SerializedPath) {
149+
$attributeMetadata->setSerializedName($attribute->getSerializedName());
150+
} elseif ($attribute instanceof SerializedPath) {
151151
if (!$accessorOrMutator) {
152152
throw new MappingException(\sprintf('SerializedPath on "%s::%s()" cannot be added. SerializedPath can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
153153
}
154154

155-
$attributeMetadata->setSerializedPath($annotation->getSerializedPath());
156-
} elseif ($annotation instanceof Ignore) {
155+
$attributeMetadata->setSerializedPath($attribute->getSerializedPath());
156+
} elseif ($attribute instanceof Ignore) {
157157
if ($accessorOrMutator) {
158158
$attributeMetadata->setIgnore(true);
159159
}
160-
} elseif ($annotation instanceof Context) {
160+
} elseif ($attribute instanceof Context) {
161161
if (!$accessorOrMutator) {
162162
throw new MappingException(\sprintf('Context on "%s::%s()" cannot be added. Context can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
163163
}
164164

165-
$this->setAttributeContextsForGroups($annotation, $attributeMetadata);
165+
$this->setAttributeContextsForGroups($attribute, $attributeMetadata);
166166
}
167167

168168
$loaded = true;
@@ -195,12 +195,12 @@ private function loadAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionPr
195195
}
196196
}
197197

198-
private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
198+
private function setAttributeContextsForGroups(Context $attribute, AttributeMetadataInterface $attributeMetadata): void
199199
{
200-
$context = $annotation->getContext();
201-
$groups = $annotation->getGroups();
202-
$normalizationContext = $annotation->getNormalizationContext();
203-
$denormalizationContext = $annotation->getDenormalizationContext();
200+
$context = $attribute->getContext();
201+
$groups = $attribute->getGroups();
202+
$normalizationContext = $attribute->getNormalizationContext();
203+
$denormalizationContext = $attribute->getDenormalizationContext();
204204

205205
if ($normalizationContext || $context) {
206206
$attributeMetadata->setNormalizationContextForGroups($normalizationContext ?: $context, $groups);

src/Symfony/Component/Serializer/Tests/Annotation/ContextTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/ContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Attribute\Context;

src/Symfony/Component/Serializer/Tests/Annotation/DiscriminatorMapTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/DiscriminatorMapTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Attribute\DiscriminatorMap;
@@ -22,16 +22,16 @@ class DiscriminatorMapTest extends TestCase
2222
{
2323
public function testGetTypePropertyAndMapping()
2424
{
25-
$annotation = new DiscriminatorMap(typeProperty: 'type', mapping: [
25+
$attribute = new DiscriminatorMap(typeProperty: 'type', mapping: [
2626
'foo' => 'FooClass',
2727
'bar' => 'BarClass',
2828
]);
2929

30-
$this->assertEquals('type', $annotation->getTypeProperty());
30+
$this->assertEquals('type', $attribute->getTypeProperty());
3131
$this->assertEquals([
3232
'foo' => 'FooClass',
3333
'bar' => 'BarClass',
34-
], $annotation->getMapping());
34+
], $attribute->getMapping());
3535
}
3636

3737
public function testExceptionWithEmptyTypeProperty()

src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/GroupsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Attribute\Groups;

src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/MaxDepthTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Attribute\MaxDepth;

src/Symfony/Component/Serializer/Tests/Annotation/SerializedNameTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/SerializedNameTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Serializer\Attribute\SerializedName;

src/Symfony/Component/Serializer/Tests/Annotation/SerializedPathTest.php renamed to src/Symfony/Component/Serializer/Tests/Attribute/SerializedPathTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests\Annotation;
12+
namespace Symfony\Component\Serializer\Tests\Attribute;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\PropertyAccess\PropertyPath;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
1313

1414
use Symfony\Component\Serializer\Attribute\Groups;
15-
use Symfony\Component\Serializer\Tests\Fixtures\ChildOfGroupsAnnotationDummy;
15+
use Symfony\Component\Serializer\Tests\Fixtures\ChildOfGroupsAttributeDummy;
1616

1717
/**
1818
* @author Kévin Dunglas <[email protected]>
@@ -23,7 +23,7 @@ class GroupDummy extends GroupDummyParent implements GroupDummyInterface
2323
private $foo;
2424
#[Groups(['b', 'c', 'name_converter'])]
2525
protected $bar;
26-
#[ChildOfGroupsAnnotationDummy]
26+
#[ChildOfGroupsAttributeDummy]
2727
protected $quux;
2828
private $fooBar;
2929
private $symfony;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
44

5-
class IgnoreDummyAdditionalGetterWithoutIgnoreAnnotations
5+
class IgnoreDummyAdditionalGetterWithoutIgnoreAttributes
66
{
77
private $myValue;
88

src/Symfony/Component/Serializer/Tests/Fixtures/ChildOfGroupsAnnotationDummy.php renamed to src/Symfony/Component/Serializer/Tests/Fixtures/ChildOfGroupsAttributeDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Serializer\Attribute\Groups;
66

77
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
8-
final class ChildOfGroupsAnnotationDummy extends Groups
8+
final class ChildOfGroupsAttributeDummy extends Groups
99
{
1010
public function __construct()
1111
{

0 commit comments

Comments
 (0)