8000 feature #58047 [Webhook] Pass original request to `RequestParserInter… · symfony/symfony@c3bb47a · GitHub
[go: up one dir, main page]

Skip to content

Commit c3bb47a

Browse files
committed
feature #58047 [Webhook] Pass original request to RequestParserInterface (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [Webhook] Pass original request to `RequestParserInterface` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #57195 | License | MIT Allows to forge the success/failure response of the webhook depending on the data of the request received by the webhook controller. Commits ------- e19067b [Webhook] Pass original request to `RequestParserInterface`
2 parents e021fd4 + e19067b commit c3bb47a

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/Symfony/Component/Webhook/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `PayloadSerializerInterface` with implementations to decouple the remote event handling from the Serializer component
8+
* Add optional `$request` argument to `RequestParserInterface::createSuccessfulResponse()` and `RequestParserInterface::createRejectedResponse()`
89

910
6.4
1011
---

src/Symfony/Component/Webhook/Client/AbstractRequestParser.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ public function parse(Request $request, #[\SensitiveParameter] string $secret):
2929
return $this->doParse($request, $secret);
3030
}
3131

32-
public function createSuccessfulResponse(): Response
32+
/**
33+
* @param Request|null $request The original request that was received by the webhook controller
34+
*/
35+
public function createSuccessfulResponse(/* ?Request $request = null */): Response
3336
{
3437
return new Response('', 202);
3538
}
3639

37-
public function createRejectedResponse(string $reason): Response
40+
/**
41+
* @param Request|null $request The original request that was received by the webhook controller
42+
*/
43+
public function createRejectedResponse(string $reason/* , ?Request $request = null */): Response
3844
{
3945
return new Response($reason, 406);
4046
}

src/Symfony/Component/Webhook/Client/RequestParserInterface.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ interface RequestParserInterface
3030
*/
3131
public function parse(Request $request, #[\SensitiveParameter] string $secret): ?RemoteEvent;
3232

33-
public function createSuccessfulResponse(): Response;
33+
/**
34+
* @param Request|null $request The original request that was received by the webhook controller
35+
*/
36+
public function createSuccessfulResponse(/* ?Request $request = null */): Response;
3437

35-
public function createRejectedResponse(string $reason): Response;
38+
/**
39+
* @param Request|null $request The original request that was received by the webhook controller
40+
*/
41+
public function createRejectedResponse(string $reason/* , ?Request $request = null */): Response;
3642
}

src/Symfony/Component/Webhook/Controller/WebhookController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function handle(string $type, Request $request): Response
4242
$parser = $this->parsers[$type]['parser'];
4343

4444
if (!$event = $parser->parse($request, $this->parsers[$type]['secret'])) {
45-
return $parser->createRejectedResponse('Unable to parse the webhook payload.');
45+
return $parser->createRejectedResponse('Unable to parse the webhook payload.', $request);
4646
}
4747

4848
$this->bus->dispatch(new ConsumeRemoteEventMessage($type, $event));
4949

50-
return $parser->createSuccessfulResponse();
50+
return $parser->createSuccessfulResponse($request);
5151
}
5252
}

0 commit comments

Comments
 (0)
0