-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Update ListenerMakeCommand.php #19660
Conversation
Allow to make listeners for the events outside of App or Illuminate namespaces
@@ -54,7 +54,8 @@ protected function buildClass($name) | |||
$event = $this->option('event'); | |||
|
|||
if (! Str::startsWith($event, $this->laravel->getNamespace()) && | |||
! Str::startsWith($event, 'Illuminate')) { | |||
! Str::startsWith($event, 'Illuminate') && | |||
! Str::startsWith($event, '\\')) { |
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.
Why calling Str::startsWith
3 times? You can call it only once:
$prefixes = [
$this->laravel->getNamespace(),
'Illuminate',
'\\',
];
if (! Str::startsWith($event, $prefixes) {
// ...
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 was called 2 times, so I figured this is a standard practice in Laravel...
Could we call it with anonymous array, to signify that it will not be used anywhere else?
if (! Str::startsWith($event, [
$this->laravel->getNamespace(),
'Illuminate',
'\\',
]) {
// ...
So where does this actually place the generated event? |
@taylorotwell |
Pass all prefixes to `Str::startWith()` in anonymous array. instead of calling it 3 times (even more useful if more prefixes will be added later on).
Allow to make listeners for the events outside of App or Illuminate namespaces, passing event class with absolute path: