-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config option to enable/disable unique token #212
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,16 +23,20 @@ public function packageBooted() | |
{ | ||
Route::macro('webhooks', function (string $url, string $name = 'default', $method = 'post') { | ||
|
||
if(! in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) { | ||
if (! in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) { | ||
throw InvalidMethod::make($method); | ||
} | ||
|
||
if (config('webhook-client.add_unique_token_to_route_name', false)) { | ||
$name .= Str::random(8); | ||
it-can marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController') | ||
->name("webhook-client-{$name}." . Str::random(8)); | ||
->name("webhook-client-{$name}"); | ||
}); | ||
|
||
$this->app->scoped(WebhookConfigRepository::class, function () { | ||
$configRepository = new WebhookConfigRepository(); | ||
$configRepository = new WebhookConfigRepository; | ||
|
||
collect(config('webhook-client.configs')) | ||
->map(fn (array $config) => new WebhookConfig($config)) | ||
|
@@ -44,9 +48,13 @@ public function packageBooted() | |
$this->app->bind(WebhookConfig::class, function () { | ||
$routeName = Route::currentRouteName() ?? ''; | ||
|
||
$routeNameSuffix = Str::after($routeName, 'webhook-client-'); | ||
$configName = Str::after($routeName, 'webhook-client-'); | ||
|
||
$configName = Str::before($routeNameSuffix, '.'); | ||
if (config('webhook-client.add_unique_token_to_route_name', false)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @it-can I think this should probably default to true since the shared route names already break route caching and there is a documented feature that causes that scenario. I can definitely see the benefit of calling the routes by name but route naming is more of an underlying structure of the package and not a documented feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @freekmurze can decide on this one too... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be set to For a next major version, I'll consider setting it to |
||
$routeNameSuffix = Str::after($routeName, 'webhook-client-'); | ||
|
||
$configName = Str::before($routeNameSuffix, '.'); | ||
} | ||
|
||
$webhookConfig = app(WebhookConfigRepository::class)->getConfig($configName); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@it-can Just personal preference but I would probably simplify this to
'tokenize_route_name'
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think @freekmurze should decide on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although
tokenize_route_name
would be good I thinkadd_unique_token_to_route_name
is more clear / human.