Completed
Pull Request — master (#6)
by ARCANEDEV
09:01
created

CurrenciesServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
1
<?php namespace Arcanedev\Currencies;
2
3
use Arcanedev\Support\PackageServiceProvider;
4
5
/**
6
 * Class     CurrenciesServiceProvider
7
 *
8
 * @package  Arcanedev\Currencies
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class CurrenciesServiceProvider extends PackageServiceProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Vendor name.
19
     *
20
     * @var string
21
     */
22
    protected $vendor  = 'arcanedev';
23
24
    /**
25
     * Package name.
26
     *
27
     * @var string
28
     */
29
    protected $package = 'currencies';
30
31
    /**
32
     * Indicates if loading of the provider is deferred.
33
     *
34
     * @var bool
35
     */
36
    protected $defer = true;
37
38
    /* ------------------------------------------------------------------------------------------------
39
     |  Getters & Setters
40
     | ------------------------------------------------------------------------------------------------
41
     */
42
    /**
43
     * Get the base path of the package.
44
     *
45
     * @return string
46
     */
47 444
    public function getBasePath()
48
    {
49 444
        return dirname(__DIR__);
50
    }
51
52
    /* ------------------------------------------------------------------------------------------------
53
     |  Main Functions
54
     | ------------------------------------------------------------------------------------------------
55
     */
56
    /**
57
     * Register the service provider.
58
     */
59 444
    public function register()
60
    {
61 444
        $this->registerConfig();
62
63 444
        $this->registerCurrencyManager();
64 444
        $this->registerCurrencyConverter();
65
66 444
        $this->app->register(Validators\ValidationServiceProvider::class);
67 444
    }
68
69
    /**
70
     * Boot the service provider.
71
     */
72 444
    public function boot()
73
    {
74 444
        parent::boot();
75
76 444
        $this->loadCurrencies();
77
78
        // Publishes
79 444
        $this->publishConfig();
80 444
        $this->publishTranslations();
81 444
    }
82
83
    /**
84
     * Get the services provided by the provider.
85
     *
86
     * @return array
87
     */
88 24
    public function provides()
89
    {
90
        return [
91 24
            'arcanedev.currencies.manager',
92 18
            Contracts\CurrencyManager::class,
93 18
            'arcanedev.currencies.converter',
94 18
            Contracts\ConverterManager::class,
95 18
        ];
96
    }
97
98
    /* ------------------------------------------------------------------------------------------------
99
     |  Other Functions
100
     | ------------------------------------------------------------------------------------------------
101
     */
102 444
    private function registerCurrencyManager()
103
    {
104
        $this->singleton('arcanedev.currencies.manager', function ($app) {
105
            /** @var \Illuminate\Contracts\Config\Repository $config */
106 444
            $config  = $app['config'];
107
108 444
            return new CurrencyManager($config->get('currencies'));
109 444
        });
110
111 444
        $this->app->bind(Contracts\CurrencyManager::class, 'arcanedev.currencies.manager');
112 444
    }
113
114
    private function registerCurrencyConverter()
115
    {
116 444
        $this->singleton('arcanedev.currencies.converter', function ($app) {
117
            return new ConverterManager($app);
118 444
        });
119
120 444
        $this->app->bind(Contracts\ConverterManager::class, 'arcanedev.currencies.converter');
121 444
    }
122
123 444
    private function loadCurrencies()
124
    {
125
        /** @var \Illuminate\Contracts\Config\Repository $config */
126 444
        $config  = $this->app['config'];
127
128
        /** @var CurrencyManager $manager */
129 444
        $manager = $this->app->make('arcanedev.currencies.manager');
130 444
        $manager->load($config->get('currencies.data', []));
131 444
    }
132
}
133