Completed
Push — master ( 8e2f81...c48e82 )
by ARCANEDEV
19:34
created

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