Completed
Push — master ( 6548c4...af3535 )
by ARCANEDEV
06:49
created

ServiceProvider::addFacade()   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 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 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 27
    public function __construct(Application $app)
50
    {
51 27
        parent::__construct($app);
52
53 27
        $this->aliasLoader = AliasLoader::getInstance();
54 27
    }
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 a service provider.
93
     *
94
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
95
     * @param  array                                       $options
96
     * @param  bool                                        $force
97
     *
98
     * @return \Illuminate\Support\ServiceProvider
99
     */
100
    protected function registerProvider($provider, array $options = [], $force = false)
101
    {
102
        return $this->app->register($provider, $options, $force);
103
    }
104
105
    /**
106
     * Register multiple service providers.
107
     *
108
     * @param  array  $providers
109
     */
110
    protected function registerProviders(array $providers)
111
    {
112
        foreach ($providers as $provider) {
113
            $this->registerProvider($provider);
114
        }
115
    }
116
117
    /**
118
     * Register a console service provider.
119
     *
120
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
121
     * @param  array                                       $options
122
     * @param  bool                                        $force
123
     *
124
     * @return \Illuminate\Support\ServiceProvider|null
125
     */
126
    protected function registerConsoleServiceProvider($provider, array $options = [], $force = false)
127
    {
128
        return $this->app->runningInConsole()
129
            ? $this->registerProvider($provider, $options, $force)
130
            : null;
131
    }
132
133
    /**
134
     * Register aliases (Facades).
135
     */
136
    protected function registerAliases()
137
    {
138
        $loader = $this->aliasLoader;
139
140
        $this->app->booting(function() use ($loader) {
141
            foreach ($this->aliases as $class => $alias) {
142
                $loader->alias($class, $alias);
143
            }
144
        });
145
    }
146
147
    /**
148
     * Add an aliases to the loader.
149
     *
150
     * @param  array  $aliases
151
     *
152
     * @return self
153
     */
154
    protected function aliases(array $aliases)
155
    {
156
        foreach ($aliases as $class => $alias) {
157
            $this->alias($class, $alias);
158
        }
159
160
        return $this;
161
    }
162
163
    /**
164
     * Add an alias to the loader.
165
     *
166
     * @param  string  $class
167
     * @param  string  $alias
168
     *
169
     * @return self
170
     */
171
    protected function alias($class, $alias)
172
    {
173
        $this->aliases[$class] = $alias;
174
175
        return $this;
176
    }
177
178
    /* ------------------------------------------------------------------------------------------------
179
     |  Services
180
     | ------------------------------------------------------------------------------------------------
181
     */
182
    /**
183
     * Get the config repository instance.
184
     *
185
     * @return \Illuminate\Config\Repository
186
     */
187
    protected function config()
188
    {
189
        return $this->app['config'];
190
    }
191
192
    /**
193
     * Get the filesystem instance.
194
     *
195
     * @return \Illuminate\Filesystem\Filesystem
196
     */
197
    protected function filesystem()
198
    {
199
        return $this->app['files'];
200
    }
201
}
202