diff --git a/src/Events/EventServiceProvider.php b/src/Events/EventServiceProvider.php index 07b72665..ac0ce1c5 100644 --- a/src/Events/EventServiceProvider.php +++ b/src/Events/EventServiceProvider.php @@ -7,6 +7,7 @@ use Phenix\Events\Console\MakeEvent; use Phenix\Events\Console\MakeListener; use Phenix\Events\Contracts\EventEmitter as EventEmitterContract; +use Phenix\Facades\File; use Phenix\Providers\ServiceProvider; class EventServiceProvider extends ServiceProvider @@ -21,17 +22,27 @@ public function provides(string $id): bool return in_array($id, $this->provides); } - public function register(): void + public function boot(): void { $this->getContainer()->addShared(EventEmitter::class, EventEmitter::class); $this->getContainer()->add(EventEmitterContract::class, EventEmitter::class); - } - public function boot(): void - { $this->commands([ MakeEvent::class, MakeListener::class, ]); + + $this->loadEvents(); + } + + private function loadEvents(): void + { + $eventPath = base_path('events'); + + if (File::exists($eventPath)) { + foreach (File::listFilesRecursively($eventPath, '.php') as $file) { + require $file; + } + } } } diff --git a/tests/fixtures/application/events/app.php b/tests/fixtures/application/events/app.php new file mode 100644 index 00000000..d61788de --- /dev/null +++ b/tests/fixtures/application/events/app.php @@ -0,0 +1,10 @@ +