Skip to content

Conversation

@zanozik
Copy link
Contributor

@zanozik zanozik commented Jun 18, 2017

Allow to make listeners for the events outside of App or Illuminate namespaces, passing event class with absolute path:

php artisan make:listener UserCustomListener -e "\Vendor\Package\Events\PackageEvent"

Allow to make listeners for the events outside of App or Illuminate namespaces
if (! Str::startsWith($event, $this->laravel->getNamespace()) &&
! Str::startsWith($event, 'Illuminate')) {
! Str::startsWith($event, 'Illuminate') &&
! Str::startsWith($event, '\\')) {
Copy link
Contributor

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) {
// ...

Copy link
Contributor Author

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',
    '\\',
]) {
// ...

@taylorotwell
Copy link
Member

So where does this actually place the generated event?

@zanozik
Copy link
Contributor Author

zanozik commented Jun 18, 2017

@taylorotwell
make:listener only makes a listener for defined event. You thinking event:generate, maybe?
In any case, I find it very useful, if I create an event in my package and fire it when a package needs it letting a user create a custom listener by running php artisan make:listener UserCustomListener -e "\Vendor\Package\Events\MyPackageEvent".
I found it strange that we can make an outside listener only for Illuminate*, even though there is no restriction on listeners created manually...

zanozik added 2 commits June 18, 2017 21:33
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).
@taylorotwell taylorotwell merged commit 346d352 into laravel:master Jun 19, 2017
@zanozik zanozik deleted the patch-1 branch June 19, 2017 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants