Skip to content
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

Laravel doesn't support event discovery if used within a package #32313

Closed
WoLfulus opened this issue Apr 9, 2020 · 1 comment
Closed

Laravel doesn't support event discovery if used within a package #32313

WoLfulus opened this issue Apr 9, 2020 · 1 comment

Comments

@WoLfulus
Copy link

WoLfulus commented Apr 9, 2020

  • Laravel Version: 7.5.2
  • PHP Version: 7.4.3
  • Database Driver & Version: n/a

Description:

It seems that classFromFile doesn't resolve the class name correctly from packages.
Also, might be related to #28187 and #28121.

Steps To Reproduce:

  • Create a package
  • Create some listeners under Listeners folder
  • Create an event service provider for the package and register it for loading
<?php

declare(strict_types=1);

namespace My\Package;

use Illuminate\Foundation\Support\Providers\EventServiceProvider;

class EventsProvider extends EventServiceProvider
{
    public function shouldDiscoverEvents(): bool
    {
        return true;
    }

    public function discoverEventsWithin(): array
    {
        return [
            __DIR__.'/Listeners'
        ];
    }
}
  • Install the package on a project
  • php artisan event:list no events loaded

Events won't be discovered because classFromFile will return Vendor\my\package\Listeners\ListenerName instead of My\Package\Listeners\MyListener.

https://github.com/laravel/framework/blob/7.x/src/Illuminate/Foundation/Events/DiscoverEvents.php#L75

The error is supressed with a continue

https://github.com/laravel/framework/blob/7.x/src/Illuminate/Foundation/Events/DiscoverEvents.php#L47

I'm wondering, is this going to be supported eventually?

@driesvints
Copy link
Member

Event discovery is only available for your app atm. If you want this to be supported feel free to open an issue on the ideas repo.

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

No branches or pull requests

2 participants