File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
tests/fixtures/application/events Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 77use Phenix \Events \Console \MakeEvent ;
88use Phenix \Events \Console \MakeListener ;
99use Phenix \Events \Contracts \EventEmitter as EventEmitterContract ;
10+ use Phenix \Facades \File ;
1011use Phenix \Providers \ServiceProvider ;
1112
1213class EventServiceProvider extends ServiceProvider
@@ -21,17 +22,27 @@ public function provides(string $id): bool
2122 return in_array ($ id , $ this ->provides );
2223 }
2324
24- public function register (): void
25+ public function boot (): void
2526 {
2627 $ this ->getContainer ()->addShared (EventEmitter::class, EventEmitter::class);
2728 $ this ->getContainer ()->add (EventEmitterContract::class, EventEmitter::class);
28- }
2929
30- public function boot (): void
31- {
3230 $ this ->commands ([
3331 MakeEvent::class,
3432 MakeListener::class,
3533 ]);
34+
35+ $ this ->loadEvents ();
36+ }
37+
38+ private function loadEvents (): void
39+ {
40+ $ eventPath = base_path ('events ' );
41+
42+ if (File::exists ($ eventPath )) {
43+ foreach (File::listFilesRecursively ($ eventPath , '.php ' ) as $ file ) {
44+ require $ file ;
45+ }
46+ }
3647 }
3748}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Phenix \Events \Contracts \Event as EventContract ;
6+ use Phenix \Facades \Event ;
7+
8+ Event::on ('user.registered ' , function (EventContract $ event ): void {
9+ // Handle the user registered event
10+ });
You can’t perform that action at this time.
0 commit comments