symfony/webhook
Symfony Webhook simplifies sending and consuming webhooks in Symfony apps. It provides tools to define webhook endpoints, validate and process incoming payloads, and dispatch outgoing webhooks with a consistent, reusable workflow.
Pros:
WebhookSender for outbound notifications or the WebhookReceiver for inbound events without coupling to the entire component.$parser = new class implements RequestParserInterface {
public function parse(Request $request): RemoteEvent {
return new RemoteEvent('stripe.payment_succeeded', json_decode($request->getContent(), true));
}
};
Cons:
Illuminate\Http\Request). Requires TPM to document trade-offs (e.g., Symfony’s Request vs. Laravel’s Request).HttpFoundation (~1MB), which may be overkill for lightweight projects. TPM should assess if this conflicts with existing Symfony packages (e.g., symfony/http-client).WebhookReceiver as a Laravel middleware for inbound validation.WebhookSender as a Laravel service for dependency injection.WebhookReceived) to decouple business logic.WebhookReceiver.Http::post() calls with WebhookSender for structured payloads (e.g., Slack notifications).// Inbound: Validate and parse a GitHub webhook
$receiver = new WebhookReceiver(
new GitHubRequestParser(),
new WebhookValidator('secret')
);
$events = $receiver->handle($request);
// Outbound: Send a Slack notification via queue
Webhook::send('https://slack.com/webhook', ['text' => 'Deploy failed'])
->withRetry(3)
->dispatch();
symfony/http-client). Mitigate by pinning versions in composer.json.config or environment variables.Webhook::send()) to abstract Symfony’s API?Log::channel())?Webhook component as Laravel services with custom bindings:
// app/Providers/WebhookServiceProvider.php
public function register() {
$this->app->singleton(WebhookSender::class, function ($app) {
return new WebhookSender(
$app->make(HttpClientInterface::class),
$app->make(SerializerInterface::class)
);
});
}
// app/Facades/Webhook.php
public static function send(string $url, array $payload): void {
app(WebhookSender::class)->send($url, $payload);
}
WebhookReceiver in Laravel middleware for inbound validation:
// app/Http/Middleware/ValidateWebhook.php
public function handle(Request $request, Closure $next) {
$receiver = new WebhookReceiver(
new CustomRequestParser(),
new WebhookValidator(config('services.webhook.secret'))
);
$receiver->handle($request);
return $next($request);
}
WebhookReceived, WebhookFailed):
// Listen for webhook events
event(new WebhookReceived($payload, $signature));
// Trigger webhooks on Laravel events
event(new OrderPaid($order))->then(function ($event) {
Webhook::send('https://slack.com/webhook', ['text' => 'Order paid']);
});
Webhook::send('https://stripe.com/webhook')
->withRetry(3)
->dispatch(); // Uses Laravel's queue system
| Phase | Task | Laravel Integration Point | Risk Level |
|---|---|---|---|
| 1 | Add symfony/webhook to composer.json |
composer require symfony/webhook |
Low |
| 2 | Create Laravel service provider for Symfony’s Webhook component |
app/Providers/WebhookServiceProvider.php |
Low |
| 3 | Implement inbound validation middleware | app/Http/Middleware/ValidateWebhook.php |
Medium |
| 4 | Replace custom outbound webhook calls with WebhookSender |
Facade/Service methods | Medium |
| 5 | Add event listeners for webhook lifecycle | Laravel Events (events/webhook.php) |
Low |
| 6 | Integrate with Laravel Queues for async retries | Queue workers (app/Jobs/SendWebhook.php) |
High |
symfony/http-client). Mitigate by:
composer.json:
"symfony/http-client": "^6
How can I help you explore Laravel packages today?