Test Setup Failed
Push — master ( 6a2c8e...43bc2f )
by Php Easy Api
04:09
created

BootLoader::logger()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Foundation\Bootstrapper;
4
5
use Resta\Router\Route;
6
use Resta\Support\Utils;
7
use Resta\Url\UrlProvider;
8
use Resta\Router\RouteProvider;
9
use Resta\Logger\LoggerProvider;
10
use Resta\Config\ConfigProvider;
11
use Resta\Console\ConsoleProvider;
12
use Resta\Contracts\BootContracts;
13
use Resta\Provider\ServiceProvider;
14
use Resta\Response\ResponseProvider;
15
use Resta\Middleware\MiddlewareProvider;
16
use Resta\Foundation\ApplicationProvider;
17
use Resta\Environment\EnvironmentProvider;
18
use Resta\Encrypter\EncrypterProvider as EncrypterProvider;
19
20
class BootLoader extends ApplicationProvider implements BootContracts
21
{
22
    /**
23
     * @var string
24
     */
25
    private $bootstrapper;
26
27
    /**
28
     * app console method
29
     *
30
     * @return mixed|void
31
     */
32
    private function console()
33
    {
34
        //if the console is true
35
        //console app runner
36
        if($this->app->runningInConsole()
37
            && $this->app['isAvailableStore'] && $this->app->checkBindings('appConsole')===false){
38
39
            //If the second parameter is sent true to the application builder,
40
            //all operations are performed by the console and the custom booting are executed
41
            $this->app->share('appConsole',ConsoleProvider::class);
42
        }
43
    }
44
45
    /**
46
     * default distributor boot method
47
     *
48
     * @return void
49
     */
50
    public function boot()
51
    {
52
        $this->{$this->bootstrapper}();
53
    }
54
55
    /**
56
     * config provider boot
57
     *
58
     * @return mixed|void
59
     */
60
    private function config()
61
    {
62
        // this is your application's config installer.
63
        // you can easily access the config variables with the config installer.
64
        if($this->app->checkBindings('config')===false){
65
            $this->app->share('config',function($app){
66
                return $app['revision']['config'] ?? ConfigProvider::class;
67
            });
68
        }
69
    }
70
71
    /**
72
     * encrypter boot
73
     *
74
     * @return mixed|void
75
     */
76
    private function encrypter()
77
    {
78
        // the rest system will assign a random key to your application for you.
79
        // this application will single the advantages of using the rest system for your application in particular.
80
        if(core()->isAvailableStore && $this->app->checkBindings('encrypter')===false){
81
            $this->app->make('encrypter',function($app){
82
                return $app['revision']['encrypter'] ?? EncrypterProvider::class;
83
            });
84
        }
85
    }
86
87
    /**
88
     * environment boot
89
     *
90
     * @return mixed|void
91
     */
92
    private function environment()
93
    {
94
        // it is often helpful to have different configuration values based onUrlParseApplication
95
        // the environment where the application is running.for example,
96
        // you may wish to use a different cache driver locally than you do on your production server.
97
        if($this->app->checkBindings('environment')===false){
98
            $this->app->share('environment',function($app){
99
                return $app['revision']['environment'] ?? EnvironmentProvider::class;
100
            });
101
        }
102
    }
103
104
    /**
105
     * event dispatcher boot
106
     *
107
     * @return mixed|void
108
     */
109
    private function eventDispatcher()
110
    {
111
        // the eventDispatcher component provides tools
112
        // that allow your application components to communicate
113
        // with each other by dispatching events and listening to them.
114
        if($this->app->checkBindings('eventDispatcher')===false){
115
            $this->app->share('eventDispatcher',function($app){
116
                if(Utils::isNamespaceExists(app()->namespace()->serviceEventDispatcher())){
117
                    return $app['revision']['eventDispatcher'] ?? app()->namespace()->serviceEventDispatcher();
118
                }
119
            });
120
        }
121
122
    }
123
124
    /**
125
     * logger boot
126
     *
127
     * @return mixed|void
128
     */
129
    private function logger()
130
    {
131
        // to help you learn more about what's happening within your application,
132
        // rest system provides robust logging services that allow you to log messages to files,
133
        // the system error log, and even to Slack to notify your entire team.
134
        if($this->app->checkBindings('logger')===false){
135
            $this->app->share('logger',function($app){
136
                return $app['revision']['logger'] ?? LoggerProvider::class;
137
            });
138
        }
139
140
    }
141
142
    /**
143
     * middleware boot
144
     *
145
     * @return mixed|void
146
     */
147
    private function middleware()
148
    {
149
        // when your application is requested, the middleware classes are running before all bootstrapper executables.
150
        // thus, if you make http request your application, you can verify with an intermediate middleware layer
151
        // and throw an exception.
152
        if($this->app->checkBindings('middleware')===false){
153
            $this->app->make('middleware',function($app){
154
                return $app['revision']['middleware'] ?? MiddlewareProvider::class;
155
            });
156
        }
157
    }
158
159
    /**
160
     * response manager boot
161
     *
162
     * @return mixed|void
163
     */
164
    private function response()
165
    {
166
        // we determine kind of output with the response manager
167
        // json as default or [xml,wsdl]
168
        if($this->app->checkBindings('response')===false){
169
            $this->app->make('response',function($app){
170
                return $app['revision']['response'] ?? ResponseProvider::class;
171
            });
172
        }
173
    }
174
175
    /**
176
     * router boot
177
     *
178
     * @return mixed|void
179
     */
180
    private function route()
181
    {
182
        // route operations are the last part of the system run. In this section,
183
        // a route operation is passed through the url process and output is sent to the screen according to
184
        // the method file to be called by the application
185
        if(core()->isAvailableStore && $this->app->checkBindings('route')===false){
186
            $this->app->share('route',function($app){
187
                return $app['revision']['route'] ?? Route::class;
188
            });
189
        }
190
    }
191
192
    /**
193
     * router boot
194
     *
195
     * @return mixed|void
196
     */
197
    private function router()
198
    {
199
        // route operations are the last part of the system run. In this section,
200
        // a route operation is passed through the url process and output is sent to the screen according to
201
        // the method file to be called by the application
202
        if(core()->isAvailableStore && $this->app->checkBindings('router')===false){
203
            $this->app->make('router',function($app){
204
                return $app['revision']['router'] ?? RouteProvider::class;
205
            });
206
        }
207
    }
208
209
    /**
210
     * service provider boot
211
     *
212
     * @return mixed|void
213
     */
214
    private function serviceProvider()
215
    {
216
        if($this->app->checkBindings('serviceProvider')===false){
217
            $this->app->share('serviceProvider',function($app){
218
                return $app['revision']['serviceProvider'] ?? ServiceProvider::class;
219
            });
220
        }
221
    }
222
223
    /**
224
     * set bootstrapper property
225
     *
226
     * @param string $bootstrapper
227
     */
228
    public function setBootstrapper($bootstrapper)
229
    {
230
        $this->bootstrapper = $bootstrapper;
231
    }
232
233
    /**
234
     * url provider boot
235
     *
236
     * @return mixed|void
237
     */
238
    private function url()
239
    {
240
        // with url parsing,the application route for
241
        // the rest project is determined after the route variables from the URL are assigned to the kernel url object.
242
        if(count(array_filter(Utils::getRequestPathInfo(),'strlen'))
243
            && $this->app->checkBindings('url')===false){
244
            $this->app->make('url',function($app){
245
                return $app['revision']['url'] ?? UrlProvider::class;
246
            });
247
        }
248
    }
249
250
    /**
251
     * special revision boot
252
     *
253
     * @param $name
254
     * @param $arguments
255
     * @return mixed
256
     */
257
    public function __call($name,$arguments)
258
    {
259
        // we use the methodological context
260
        // for kernel group values that are replaced with revision.
261
        $revisionBoot = array_search($name,app()->get('revision'));
262
        if(is_string($revisionBoot) && method_exists($this,$revisionBoot)){
263
            return $this->{$revisionBoot}();
264
        }
265
266
        exception()->badFunctionCall('There is no boot method named '.$name);
267
    }
268
}