Completed
Push — master ( 6085dd...cfd23f )
by ARCANEDEV
03:26
created

StoreManager::loadStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 9.8666
c 0
b 0
f 0
1
<?php namespace Arcanedev\Notify;
2
3
use Illuminate\Support\Manager;
4
5
/**
6
 * Class     StoreManager
7
 *
8
 * @package  Arcanedev\Notify
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class StoreManager extends Manager
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Get the default driver name.
20
     *
21
     * @return string
22
     */
23 48
    public function getDefaultDriver()
24
    {
25 48
        return $this->config()->get('notify.default', 'session');
26
    }
27
28
    /**
29
     * Load the stores.
30
     *
31
     * @return void
32
     */
33 48
    public function loadStores(): void
34
    {
35 48
        foreach ($this->config()->get('notify.stores', []) as $driver => $store) {
36 48
            $this->loadStore($driver, $store);
37
        }
38 48
    }
39
40
    /**
41
     * Load/Register a store.
42
     *
43
     * @param  string  $driver
44
     * @param  array   $store
45
     *
46
     * @return void
47
     */
48 48
    protected function loadStore(string $driver, array $store)
49
    {
50 48
        $class = $store['class'];
51
52
        $this->extend($driver, function () use ($class) {
53 48
            return $this->app->make($class);
54 48
        });
55
56
        $this->app->when($class)->needs('$options')->give(function () use ($store) {
57 48
            return $store['options'] ?? [];
58 48
        });
59 48
    }
60
61
    /* -----------------------------------------------------------------
62
     |  Other Methods
63
     | -----------------------------------------------------------------
64
     */
65
66
    /**
67
     * Get the config repository.
68
     *
69
     * @return \Illuminate\Contracts\Config\Repository
70
     */
71 48
    protected function config()
72
    {
73 48
        return $this->app['config'];
74
    }
75
}
76