JsonResponseServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace ArinaSystems\JsonResponse\Providers;
4
5
use ArinaSystems\JsonResponse\Attribute;
6
use ArinaSystems\JsonResponse\JsonResponse;
7
use ArinaSystems\JsonResponse\Option;
8
use ArinaSystems\JsonResponse\Status;
9
use Illuminate\Support\ServiceProvider;
10
11
class JsonResponseServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Boot the application events.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $this->registerConfig();
21
        $this->registerFacade();
22
    }
23
24
    /**
25
     * Register facade.
26
     *
27
     * @return void
28
     */
29
    protected function registerFacade()
30
    {
31
        $this->app->singleton('json-response.option', function ($app) {
32
            return new Option($app['config']->get('json-response'));
33
        });
34
        $this->app->singleton('json-response.attribute', function ($app) {
35
            return new Attribute($app['json-response.option']->instance());
36
        });
37
        $this->app->singleton('json-response.status', function ($app) {
38
            return new Status($app['config']->get('json-response.status'));
39
        });
40
        $this->app->singleton('json-response.builder', function ($app) {
41
            return new JsonResponse($app['json-response.option']->instance(), $app['json-response.attribute']->instance(), $app['json-response.status']->instance());
42
        });
43
    }
44
45
    /**
46
     * Register config.
47
     *
48
     * @return void
49
     */
50
    protected function registerConfig()
51
    {
52
        $this->publishes([
53
            __DIR__.'/../../config/config.php' => config_path('json-response.php'),
54
        ], 'json-response:config');
55
        $this->mergeConfigFrom(
56
            __DIR__.'/../../config/config.php',
57
            'json-response'
58
        );
59
    }
60
}
61