Completed
Push — master ( 7383a6...06d9f7 )
by ARCANEDEV
19s
created

CurrenciesServiceProvider::loadCurrencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 4
nc 1
nop 0
crap 1
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 384
    public function getBasePath()
48
    {
49 384
        return dirname(__DIR__);
50
    }
51
52
    /* ------------------------------------------------------------------------------------------------
53
     |  Main Functions
54
     | ------------------------------------------------------------------------------------------------
55
     */
56
    /**
57
     * Register the service provider.
58
     */
59 384
    public function register()
60
    {
61 384
        $this->registerConfig();
62
63 384
        $this->registerCurrencyManager();
64 384
        $this->registerCurrencyConverter();
65 384
    }
66
67
    /**
68
     * Boot the service provider.
69
     */
70 384
    public function boot()
71
    {
72 384
        parent::boot();
73
74 384
        $this->loadCurrencies();
75
76
        // Publishes
77 384
        $this->publishConfig();
78 384
    }
79
80
    /**
81
     * Get the services provided by the provider.
82
     *
83
     * @return array
84
     */
85 24
    public function provides()
86
    {
87
        return [
88 24
            'arcanedev.currencies.manager',
89 18
            Contracts\CurrencyManager::class,
90 18
            'arcanedev.currencies.converter',
91 18
            Contracts\ConverterManager::class,
92 18
        ];
93
    }
94
95
    /* ------------------------------------------------------------------------------------------------
96
     |  Other Functions
97
     | ------------------------------------------------------------------------------------------------
98
     */
99 384
    private function registerCurrencyManager()
100
    {
101
        $this->singleton('arcanedev.currencies.manager', function ($app) {
102
            /** @var \Illuminate\Contracts\Config\Repository $config */
103 384
            $config  = $app['config'];
104
105 384
            return new CurrencyManager($config->get('currencies'));
106 384
        });
107
108 384
        $this->app->bind(Contracts\CurrencyManager::class, 'arcanedev.currencies.manager');
109 384
    }
110
111
    private function registerCurrencyConverter()
112
    {
113 384
        $this->singleton('arcanedev.currencies.converter', function ($app) {
114
            return new ConverterManager($app);
115 384
        });
116
117 384
        $this->app->bind(Contracts\ConverterManager::class, 'arcanedev.currencies.converter');
118 384
    }
119
120 384
    private function loadCurrencies()
121
    {
122
        /** @var \Illuminate\Contracts\Config\Repository $config */
123 384
        $config  = $this->app['config'];
124
125
        /** @var CurrencyManager $manager */
126 384
        $manager = $this->app->make('arcanedev.currencies.manager');
127 384
        $manager->load($config->get('currencies.data', []));
128 384
    }
129
}
130