NotifyServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\Notify;
6
7
use Arcanedev\Notify\Contracts\StoreManager as StoreManagerContract;
8
use Arcanedev\Support\Providers\PackageServiceProvider;
9
use Illuminate\Contracts\Support\DeferrableProvider;
10
11
/**
12
 * Class     NotifyServiceProvider
13
 *
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class NotifyServiceProvider extends PackageServiceProvider implements DeferrableProvider
17
{
18
    /* -----------------------------------------------------------------
19
     |  Properties
20
     | -----------------------------------------------------------------
21
     */
22
23
    /**
24
     * Package name.
25
     *
26
     * @var string
27
     */
28
    protected $package = 'notify';
29
30
    /* -----------------------------------------------------------------
31
     |  Main Methods
32
     | -----------------------------------------------------------------
33
     */
34
35
    /**
36
     * Register the service provider.
37
     */
38 60
    public function register(): void
39
    {
40 60
        parent::register();
41
42 60
        $this->registerConfig();
43
44
        // Store Manager
45 30
        $this->singleton(StoreManagerContract::class, StoreManager::class);
46
47 30
        $this->app->resolving(StoreManagerContract::class, function (StoreManagerContract $manager, $app) {
48 52
            $stores = $app['config']->get('notify.stores', []);
49
50 52
            return $manager->registerStores($stores);
51 60
        });
52
53
        // Store driver
54 30
        $this->bind(Contracts\Store::class, function ($app) {
55 26
            return $app[StoreManagerContract::class]->driver();
56 60
        });
57
58
        // Notifier
59 30
        $this->singleton(Contracts\Notify::class, Notify::class);
60 60
    }
61
62
    /**
63
     * Boot the package.
64
     */
65 60
    public function boot(): void
66
    {
67 60
        if ($this->app->runningInConsole()) {
68 60
            $this->publishConfig();
69
        }
70 60
    }
71
72
    /**
73
     * Get the services provided by the provider.
74
     *
75
     * @return array
76
     */
77 4
    public function provides(): array
78
    {
79
        return [
80 4
            Contracts\Notify::class,
81
            Contracts\Store::class,
82
        ];
83
    }
84
}
85