-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathExpoNotificationsServiceProvider.php
More file actions
67 lines (56 loc) · 2.56 KB
/
ExpoNotificationsServiceProvider.php
File metadata and controls
67 lines (56 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace YieldStudio\LaravelExpoNotifier;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use YieldStudio\LaravelExpoNotifier\Commands\CheckTickets;
use YieldStudio\LaravelExpoNotifier\Commands\ClearSentNotifications;
use YieldStudio\LaravelExpoNotifier\Commands\SendPendingNotifications;
use YieldStudio\LaravelExpoNotifier\Contracts\ExpoNotificationsServiceInterface;
use YieldStudio\LaravelExpoNotifier\Contracts\ExpoPendingNotificationStorageInterface;
use YieldStudio\LaravelExpoNotifier\Contracts\ExpoTicketStorageInterface;
use YieldStudio\LaravelExpoNotifier\Contracts\ExpoTokenStorageInterface;
use YieldStudio\LaravelExpoNotifier\Events\InvalidExpoToken;
use YieldStudio\LaravelExpoNotifier\Listeners\DeleteInvalidExpoToken;
final class ExpoNotificationsServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(ExpoTokenStorageInterface::class, config('expo-notifications.drivers.token'));
$this->app->bind(ExpoTicketStorageInterface::class, config('expo-notifications.drivers.ticket'));
$this->app->bind(ExpoPendingNotificationStorageInterface::class, config('expo-notifications.drivers.notification'));
$this->app->bind(ExpoNotificationsServiceInterface::class, function ($app) {
$apiUrl = config('expo-notifications.service.api_url');
$host = config('expo-notifications.service.host');
$accessToken = config('expo-notifications.service.access_token');
return new ExpoNotificationsService(
$apiUrl,
$host,
$accessToken,
$app->make(ExpoPendingNotificationStorageInterface::class),
$app->make(ExpoTicketStorageInterface::class)
);
});
}
public function boot(): void
{
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->publishes([
__DIR__.'/../config' => config_path(),
], 'expo-notifications-config');
$this->publishes([
__DIR__.'/../database/migrations' => database_path('migrations'),
], 'expo-notifications-migration');
$this->commands([
SendPendingNotifications::class,
CheckTickets::class,
ClearSentNotifications::class,
]);
if (config('expo-notifications.automatically_delete_token', false)) {
Event::listen(
InvalidExpoToken::class,
[DeleteInvalidExpoToken::class, 'handle']
);
}
}
}