Completed
Push — master ( bbe6d6...b8c901 )
by ARCANEDEV
9s
created

ServiceProvider::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\Support;
2
3
use Illuminate\Contracts\Foundation\Application;
4
use Illuminate\Foundation\AliasLoader;
5
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6
7
/**
8
 * Class     ServiceProvider
9
 *
10
 * @package  Arcanedev\Support\Laravel
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class ServiceProvider extends IlluminateServiceProvider
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * The application instance.
21
     *
22
     * @var \Illuminate\Foundation\Application
23
     */
24
    protected $app;
25
26
    /**
27
     * The aliases collection.
28
     *
29
     * @var array
30
     */
31
    protected $aliases = [];
32
33
    /**
34
     * Alias loader.
35
     *
36
     * @var \Illuminate\Foundation\AliasLoader
37
     */
38
    private $aliasLoader;
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Constructor
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * Create a new service provider instance.
46
     *
47
     * @param  \Illuminate\Contracts\Foundation\Application  $app
48
     */
49 24
    public function __construct(Application $app)
50
    {
51 24
        parent::__construct($app);
52
53 24
        $this->aliasLoader = AliasLoader::getInstance();
54 24
    }
55
56
    /* ------------------------------------------------------------------------------------------------
57
     |  Main Functions
58
     | ------------------------------------------------------------------------------------------------
59
     */
60
    /**
61
     * Boot the service provider.
62
     */
63
    public function boot()
64
    {
65
        //
66
    }
67
68
    /**
69
     * Register a binding with the container.
70
     *
71
     * @param  string|array          $abstract
72
     * @param  \Closure|string|null  $concrete
73
     * @param  bool                  $shared
74
     */
75
    public function bind($abstract, $concrete = null, $shared = false)
76
    {
77
        $this->app->bind($abstract, $concrete, $shared);
78
    }
79
80
    /**
81
     * Register a shared binding in the container.
82
     *
83
     * @param  string|array          $abstract
84
     * @param  \Closure|string|null  $concrete
85
     */
86
    protected function singleton($abstract, $concrete = null)
87
    {
88
        $this->app->singleton($abstract, $concrete);
89
    }
90
91
    /**
92
     * Register aliases (Facades).
93
     */
94
    protected function registerAliases()
95
    {
96
        $loader = $this->aliasLoader;
97
98
        $this->app->booting(function() use ($loader) {
99
            foreach ($this->aliases as $class => $alias) {
100
                $loader->alias($class, $alias);
101
            }
102
        });
103
    }
104
105
    /**
106
     * Add an aliases to the loader.
107
     *
108
     * @param  array  $aliases
109
     *
110
     * @return self
111
     */
112
    protected function aliases(array $aliases)
113
    {
114
        foreach ($aliases as $class => $alias) {
115
            $this->alias($class, $alias);
116
        }
117
118
        return $this;
119
    }
120
121
    /**
122
     * Add an alias to the loader.
123
     *
124
     * @param  string  $class
125
     * @param  string  $alias
126
     *
127
     * @return self
128
     */
129
    protected function alias($class, $alias)
130
    {
131
        $this->aliases[$class] = $alias;
132
133
        return $this;
134
    }
135
136
    /* ------------------------------------------------------------------------------------------------
137
     |  Services
138
     | ------------------------------------------------------------------------------------------------
139
     */
140
    /**
141
     * Get the config repository instance.
142
     *
143
     * @return \Illuminate\Config\Repository
144
     */
145
    protected function config()
146
    {
147
        return $this->app['config'];
148
    }
149
150
    /**
151
     * Get the filesystem instance.
152
     *
153
     * @return \Illuminate\Filesystem\Filesystem
154
     */
155
    protected function filesystem()
156
    {
157
        return $this->app['files'];
158
    }
159
160
    /* ------------------------------------------------------------------------------------------------
161
     |  Deprecated Methods
162
     | ------------------------------------------------------------------------------------------------
163
     */
164
    /**
165
     * Add Aliases into the app.
166
     *
167
     * @deprecated 3.7.0 Use the aliases() method instead and don't forget to add the registerAliases() inside register() method.
168
     *
169
     * @param  array  $aliases
170
     *
171
     * @return self
172
     */
173
    protected function addFacades(array $aliases)
174
    {
175
        foreach ($aliases as $alias => $facade) {
176
            $this->addFacade($alias, $facade);
0 ignored issues
show
Deprecated Code introduced by
The method Arcanedev\Support\ServiceProvider::addFacade() has been deprecated with message: 3.7.0 Use the alias() method instead and don't forget to add the registerAliases() inside register() method.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
177
        }
178
179
        return $this;
180
    }
181
182
    /**
183
     * Add Alias. (Facade)
184
     *
185
     * @deprecated 3.7.0 Use the alias() method instead and don't forget to add the registerAliases() inside register() method.
186
     *
187
     * @param  string  $alias
188
     * @param  string  $facade
189
     */
190
    protected function addFacade($alias, $facade)
191
    {
192
        $this->aliasLoader->alias($alias, $facade);
193
    }
194
}
195