Skip to content

Commit a63ab4d

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: 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 8d9f588 + f777331 commit a63ab4d

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
@@ -137,6 +137,19 @@ public function testThrowsOnContextOnInvalidMethod()
137137
$loader->loadClassMetadata($classMetadata);
138138
}
139139

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

142155
abstract protected function getNamespace(): string;

0 commit comments

Comments
 (0)