Skip to content

Commit 014a167

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Update ExceptionInterface.php Revert removal of Stringable check Flush with flush() after ob_end_flush() [Validator] : Fix "PHP Warning: Undefined array key 1" in NotCompromisedPasswordValidator [Validator] Fix traverse option on Valid constraint when used as Attribute [HttpFoundation] Fix deleteFileAfterSend on client abortion Prevent that bad Ignore method annotations lead to incorrect results also fix the test fix deprecation fix sending request to paths containing multiple slashes Fix generated validation error message for wrong exception mapping status code
2 parents 916b515 + 735c2a9 commit 014a167

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

Mapping/Loader/AnnotationLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
134134

135135
$attributeMetadata->setSerializedName($annotation->getSerializedName());
136136
} elseif ($annotation instanceof Ignore) {
137+
if (!$accessorOrMutator) {
138+
throw new MappingException(sprintf('Ignore on "%s::%s()" cannot be added. Ignore can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
139+
}
140+
137141
$attributeMetadata->setIgnore(true);
138142
} elseif ($annotation instanceof Context) {
139143
if (!$accessorOrMutator) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Serializer\Tests\Fixtures\Annotations;
6+
7+
use Symfony\Component\Serializer\Annotation\Ignore;
8+
9+
class Entity45016
10+
{
11+
/**
12+
* @var int
13+
*/
14+
private $id = 1234;
15+
16+
public function getId(): int
17+
{
18+
return $this->id;
19+
}
20+
21+
/**
22+
* @Ignore()
23+
*/
24+
public function badIgnore(): bool
25+
{
26+
return true;
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes;
6+
7+
use Symfony\Component\Serializer\Annotation\Ignore;
8+
9+
class Entity45016
10+
{
11+
/**
12+
* @var int
13+
*/
14+
private $id = 1234;
15+
16+
public function getId(): int
17+
{
18+
return $this->id;
19+
}
20+
21+
#[Ignore]
22+
public function badIgnore(): bool
23+
{
24+
return true;
25+
}
26+
}

Tests/Mapping/Loader/AnnotationLoaderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ public function testThrowsOnContextOnInvalidMethod()
139139
$loader->loadClassMetadata($classMetadata);
140140
}
141141

142+
public function testCanHandleUnrelatedIgnoredMethods()
143+
{
144+
$class = $this->getNamespace().'\Entity45016';
145+
146+
$this->expectException(MappingException::class);
147+
$this->expectExceptionMessage(sprintf('Ignore on "%s::badIgnore()" cannot be added', $class));
148+
149+
$metadata = new ClassMetadata($class);
150+
$loader = $this->getLoaderForContextMapping();
151+
152+
$loader->loadClassMetadata($metadata);
153+
}
154+
142155
abstract protected function createLoader(): AnnotationLoader;
143156

144157
abstract protected function getNamespace(): string;

0 commit comments

Comments
 (0)