Completed
Push — master ( 04fd8b...0cf18b )
by ARCANEDEV
9s
created

ManagerServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
1
<?php namespace Arcanedev\Currencies\Providers;
2
3
use Arcanedev\Currencies\Contracts\ConverterManager as ConverterManagerContract;
4
use Arcanedev\Currencies\Contracts\CurrencyManager as CurrencyManagerContract;
5
use Arcanedev\Currencies\ConverterManager;
6
use Arcanedev\Currencies\CurrencyManager;
7
use Arcanedev\Support\ServiceProvider;
8
9
/**
10
 * Class     ManagerServiceProvider
11
 *
12
 * @package  Arcanedev\Currencies\Providers
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class ManagerServiceProvider extends ServiceProvider
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Properties
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = true;
27
28
    /* ------------------------------------------------------------------------------------------------
29
     |  Main Functions
30
     | ------------------------------------------------------------------------------------------------
31
     */
32
    /**
33
     * Register the service provider.
34
     */
35 468
    public function register()
36
    {
37 468
        $this->registerCurrencyManager();
38 468
        $this->registerCurrencyConverter();
39 468
    }
40
41
    /**
42
     * Boot the service provider.
43
     */
44 468
    public function boot()
45
    {
46 468
        parent::boot();
47
48 468
        $this->loadCurrencies();
49 468
    }
50
51
    /**
52
     * Get the services provided by the provider.
53
     *
54
     * @return array
55
     */
56 21
    public function provides()
57
    {
58
        return [
59 12
            'arcanedev.currencies.manager',
60 9
            CurrencyManagerContract::class,
61 18
            'arcanedev.currencies.converter',
62 9
            ConverterManagerContract::class,
63 9
        ];
64
    }
65
66
    /* ------------------------------------------------------------------------------------------------
67
     |  Other Functions
68
     | ------------------------------------------------------------------------------------------------
69
     */
70 468
    private function registerCurrencyManager()
71
    {
72
        $this->singleton('arcanedev.currencies.manager', function ($app) {
73
            /** @var \Illuminate\Contracts\Config\Repository $config */
74 468
            $config  = $app['config'];
75
76 468
            return new CurrencyManager($config->get('currencies'));
77 468
        });
78
79 468
        $this->app->bind(CurrencyManagerContract::class, 'arcanedev.currencies.manager');
80 468
    }
81
82
    private function registerCurrencyConverter()
83
    {
84 468
        $this->singleton('arcanedev.currencies.converter', function ($app) {
85
            return new ConverterManager($app);
86 468
        });
87
88 468
        $this->app->bind(ConverterManagerContract::class, 'arcanedev.currencies.converter');
89 468
    }
90
91 468
    private function loadCurrencies()
92
    {
93
        /** @var \Illuminate\Contracts\Config\Repository $config */
94 468
        $config  = $this->app['config'];
95
96
        /** @var CurrencyManagerContract $manager */
97 468
        $manager = $this->app->make('arcanedev.currencies.manager');
98 468
        $manager->load($config->get('currencies.data', []));
99 468
    }
100
}
101