Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9cb68b

Browse filesBrowse files
committed
feature #51562 [DoctrineBridge] Add message to #[MapEntity] for NotFoundHttpException (moesoha)
This PR was merged into the 7.1 branch. Discussion ---------- [DoctrineBridge] Add `message` to #[MapEntity] for NotFoundHttpException | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Allow the message in NotFoundHttpException to be overridden with the `message` argument in `#[MapEntity]`. Commits ------- 753ad20 [DoctrineBridge] Add `message` to #[MapEntity] for NotFoundHttpException
2 parents 5c7f4b0 + 753ad20 commit b9cb68b
Copy full SHA for b9cb68b

File tree

3 files changed

+5
-2
lines changed
Filter options

3 files changed

+5
-2
lines changed

‎src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
7373
}
7474

7575
if (null === $object && !$argument->isNullable()) {
76-
throw new NotFoundHttpException(sprintf('"%s" object not found by "%s".', $options->class, self::class).$message);
76+
throw new NotFoundHttpException($options->message ?? (sprintf('"%s" object not found by "%s".', $options->class, self::class).$message));
7777
}
7878

7979
return [$object];

‎src/Symfony/Bridge/Doctrine/Attribute/MapEntity.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Attribute/MapEntity.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(
4444
public ?bool $evictCache = null,
4545
bool $disabled = false,
4646
string $resolver = EntityValueResolver::class,
47+
public ?string $message = null,
4748
) {
4849
parent::__construct($resolver, $disabled);
4950
}
@@ -59,6 +60,7 @@ public function withDefaults(self $defaults, ?string $class): static
5960
$clone->stripNull ??= $defaults->stripNull ?? false;
6061
$clone->id ??= $defaults->id;
6162
$clone->evictCache ??= $defaults->evictCache ?? false;
63+
$clone->message ??= $defaults->message;
6264

6365
return $clone;
6466
}

‎src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testResolveWithConversionFailedException()
153153
$request = new Request();
154154
$request->attributes->set('id', 'test');
155155

156-
$argument = $this->createArgument('stdClass', new MapEntity(id: 'id'));
156+
$argument = $this->createArgument('stdClass', new MapEntity(id: 'id', message: 'Test'));
157157

158158
$repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
159159
$repository->expects($this->once())
@@ -167,6 +167,7 @@ public function testResolveWithConversionFailedException()
167167
->willReturn($repository);
168168

169169
$this->expectException(NotFoundHttpException::class);
170+
$this->expectExceptionMessage('Test');
170171

171172
$resolver->resolve($request, $argument);
172173
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.