diff --git a/src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php index 2db9b9d3d33c5..801c317767ac0 100644 --- a/src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php +++ b/src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php @@ -54,7 +54,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata) $classMetadata->addAttributeMetadata($attributesMetadata[$property->name]); } - if ($property->getDeclaringClass()->name == $className) { + if ($property->getDeclaringClass()->name === $className) { foreach ($this->reader->getPropertyAnnotations($property) as $groups) { if ($groups instanceof Groups) { foreach ($groups->getGroups() as $group) { @@ -68,10 +68,10 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata) } foreach ($reflectionClass->getMethods() as $method) { - if ($method->getDeclaringClass()->name == $className) { + if ($method->getDeclaringClass()->name === $className) { foreach ($this->reader->getMethodAnnotations($method) as $groups) { if ($groups instanceof Groups) { - if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) { + if (preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches)) { $attributeName = lcfirst($matches[2]); if (isset($attributesMetadata[$attributeName])) { @@ -85,7 +85,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata) $attributeMetadata->addGroup($group); } } else { - throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name)); + 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)); } } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/GroupDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/GroupDummy.php index 90d45f5b910b6..0a623d8912399 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/GroupDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/GroupDummy.php @@ -22,18 +22,21 @@ class GroupDummy extends GroupDummyParent implements GroupDummyInterface * @Groups({"a"}) */ private $foo; - /** - * @Groups({"b", "c"}) - */ protected $bar; private $fooBar; private $symfony; + /** + * @Groups({"b"}) + */ public function setBar($bar) { $this->bar = $bar; } + /** + * @Groups({"c"}) + */ public function getBar() { return $this->bar; @@ -57,7 +60,7 @@ public function setFooBar($fooBar) /** * @Groups({"a", "b"}) */ - public function getFooBar() + public function isFooBar() { return $this->fooBar; }