8000 Add option to use Groups attribute on class · symfony/symfony@95aae8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 95aae8d

Browse files
committed
Add option to use Groups attribute on class
1 parent 21c8789 commit 95aae8d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Symfony/Component/Serializer/Annotation/Groups.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*
1919
* @Annotation
2020
* @NamedArgumentConstructor
21-
* @Target({"PROPERTY", "METHOD"})
21+
* @Target({"PROPERTY", "METHOD", "CLASS"})
2222
*
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
25-
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
25+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)]
2626
class Groups
2727
{
2828
/**

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

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
5555
$reflectionClass = $classMetadata->getReflectionClass();
5656
$className = $reflectionClass->name;
5757
$loaded = false;
58+
$classGroups = [];
5859

5960
$attributesMetadata = $classMetadata->getAttributesMetadata();
6061

@@ -64,6 +65,8 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
6465
$annotation->getTypeProperty(),
6566
$annotation->getMapping()
6667
));
68+
} elseif ($annotation instanceof Groups) {
69+
$classGroups = $annotation->getGroups();
6770
}
6871
}
6972

@@ -74,6 +77,10 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
7477
}
7578

7679
if ($property->getDeclaringClass()->name === $className) {
80+
foreach ($classGroups as $group) {
81+
$attributesMetadata[$property->name]->addGroup($group);
82+
}
83+
7784
foreach ($this->loadAnnotations($property) as $annotation) {
7885
if ($annotation instanceof Groups) {
7986
foreach ($annotation->getGroups() as $group) {

0 commit comments

Comments
 (0)
0