Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/Events/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
}
}
10 changes: 10 additions & 0 deletions tests/fixtures/application/events/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Phenix\Events\Contracts\Event as EventContract;
use Phenix\Facades\Event;

Event::on('user.registered', function (EventContract $event): void {
// Handle the user registered event
});