Completed
Pull Request — master (#12)
by
unknown
02:46
created

ExpoPushNotificationsServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 19
cp 0
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace NotificationChannels\ExpoPushNotifications;
4
5
use ExponentPhpSDK\Expo;
6
use ExponentPhpSDK\ExpoRegistrar;
7
use ExponentPhpSDK\ExpoRepository;
8
use Illuminate\Support\ServiceProvider;
9
use ExponentPhpSDK\Repositories\ExpoFileDriver;
10
use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver;
11
12
class ExpoPushNotificationsServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     */
17
    public function boot()
18
    {
19
        $this->publishes([
20
            __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'),
21
        ], 'config');
22
23
        $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications');
24
25
        if (! class_exists('CreateExponentPushNotificationInterestsTable')) {
26
            $timestamp = date('Y_m_d_His', time());
27
            $this->publishes([
28
                __DIR__.'/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"),
29
            ], 'migrations');
30
        }
31
32
        $this->app->when(ExpoChannel::class)
33
            ->needs(Expo::class)
34
            ->give(function () {
35
                return new Expo(new ExpoRegistrar($this->getInterestsDriver()));
36
            });
37
38
        //Load routes
39
        $this->loadRoutesFrom(__DIR__.'/Http/routes.php');
40
    }
41
42
    /**
43
     * Register the application services.
44
     */
45
    public function register()
46
    {
47
        $this->app->bind(ExpoRepository::class, get_class($this->getInterestsDriver()));
48
    }
49
50
    /**
51
     * @return ExpoRepository
52
     */
53
    public function getInterestsDriver()
54
    {
55
        $driver = config('exponent-push-notifications.interests.driver');
56
57
        switch ($driver) {
58
            case 'database':
59
                $class = new ExpoDatabaseDriver();
60
                break;
61
            default:
62
                $class = new ExpoFileDriver();
63
        }
64
65
        return $class;
66
    }
67
}