Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Bridge/Laravel/Providers/WebhookClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use WayOfDev\WebhookClient\ConfigRepository;
use WayOfDev\WebhookClient\Contracts\WebhookCallRepository;
use WayOfDev\WebhookClient\Exceptions\InvalidConfig;
use WayOfDev\WebhookClient\Exceptions\InvalidMethod;
use WayOfDev\WebhookClient\Persistence\ORMWebhookCallRepository;

use function in_array;
use function is_null;

final class WebhookClientServiceProvider extends ServiceProvider
Expand All @@ -34,8 +36,13 @@ public function boot(): void

public function register(): void
{
Route::macro('webhooks', function (string $url, string $name = 'default') {
return Route::post($url, WebhookController::class)->name("webhook-client-{$name}");
Route::macro('webhooks', function (string $url, string $name = 'default', $method = 'post') {
if (! in_array($method, ['get', 'post', 'put', 'patch', 'delete'], true)) {
throw InvalidMethod::make($method);
}

// @phpstan-ignore-next-line
return Route::{$method}($url, WebhookController::class)->name("webhook-client-{$name}");
});

$this->app->scoped(ConfigRepository::class, function () {
Expand Down
15 changes: 15 additions & 0 deletions src/Exceptions/InvalidMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace WayOfDev\WebhookClient\Exceptions;

use Exception;

final class InvalidMethod extends Exception
{
public static function make($method): self
{
return new self("The method $method is not allowed.");
}
}