Files

47 lines
2.0 KiB
PHP

<?php
namespace App\Modules\Notifications\Infrastructure\Providers;
use App\Modules\Jobs\Domain\Events\PeopleAddedToJob;
use App\Modules\Jobs\Domain\Events\PeopleAddedToTask;
use App\Modules\Notifications\Application\Contracts\NotificationQueries;
use App\Modules\Notifications\Application\UseCases\NotifyAddedPeople;
use App\Modules\Notifications\Domain\Contracts\NotificationRepository;
use App\Modules\Notifications\Infrastructure\Persistence\Repositories\EloquentNotificationQueries;
use App\Modules\Notifications\Infrastructure\Persistence\Repositories\EloquentNotificationRepository;
use App\Modules\Notifications\Presentation\Console\NotifyMaintenanceDueCommand;
use App\Modules\Notifications\Presentation\Console\NotifyTasksStartingSoonCommand;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
/**
* Wires the Notifications module into Laravel: bindings, the
* `notifications::` Livewire namespace (the header's bell), the listeners
* of the Jobs module's assignment events and the daily command, scheduled
* in routes/console.php.
*/
class NotificationsServiceProvider extends ServiceProvider
{
/**
* @var array<class-string, class-string>
*/
public array $bindings = [
NotificationRepository::class => EloquentNotificationRepository::class,
NotificationQueries::class => EloquentNotificationQueries::class,
];
public function boot(): void
{
Livewire::addNamespace('notifications', viewPath: dirname(__DIR__, 2).'/Presentation/Livewire');
// Published by Jobs after the change is committed.
Event::listen(PeopleAddedToTask::class, fn (PeopleAddedToTask $event) => app(NotifyAddedPeople::class)->forTask($event));
Event::listen(PeopleAddedToJob::class, fn (PeopleAddedToJob $event) => app(NotifyAddedPeople::class)->forJob($event));
if ($this->app->runningInConsole()) {
$this->commands([NotifyTasksStartingSoonCommand::class, NotifyMaintenanceDueCommand::class]);
}
}
}