Completed
Push — master ( 4cc8d8...e56a52 )
by Arjay
04:43
created

DatatablesServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
c 1
b 0
f 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Yajra\Datatables;
4
5
use Collective\Html\HtmlServiceProvider;
6
use Illuminate\Support\ServiceProvider;
7
use Maatwebsite\Excel\ExcelServiceProvider;
8
use Yajra\Datatables\Generators\DataTablesMakeCommand;
9
use Yajra\Datatables\Generators\DataTablesScopeCommand;
10
11
class DatatablesServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Indicates if loading of the provider is deferred.
15
     *
16
     * @var bool
17
     */
18
    protected $defer = false;
19
20
    /**
21
     * Bootstrap the application events.
22
     *
23
     * @return void
24
     */
25
    public function boot()
26
    {
27
        $this->loadViewsFrom(__DIR__ . '/resources/views', 'datatables');
28
29
        $this->publishAssets();
30
31
        $this->registerCommands();
32
    }
33
34
    /**
35
     * Publish datatables assets.
36
     */
37
    private function publishAssets()
38
    {
39
        $this->publishes([
40
            __DIR__ . '/config/config.php' => config_path('datatables.php'),
41
        ], 'datatables');
42
43
        $this->publishes([
44
            __DIR__ . '/resources/assets/buttons.server-side.js' => public_path('vendor/datatables/buttons.server-side.js'),
45
        ], 'datatables');
46
47
        $this->publishes([
48
            __DIR__ . '/resources/views' => base_path('/resources/views/vendor/datatables'),
49
        ], 'datatables');
50
    }
51
52
    /**
53
     * Register datatables commands.
54
     */
55
    private function registerCommands()
56
    {
57
        $this->commands(DataTablesMakeCommand::class);
58
        $this->commands(DataTablesScopeCommand::class);
59
    }
60
61
    /**
62
     * Register the service provider.
63
     *
64
     * @return void
65
     */
66
    public function register()
67
    {
68
        $this->registerRequiredProviders();
69
70
        $this->app->singleton('datatables', function ($app) {
71
            return new Datatables($app->make(Request::class));
72
        });
73
74
        $this->registerAliases();
75
    }
76
77
    /**
78
     * Register 3rd party providers.
79
     */
80
    private function registerRequiredProviders()
81
    {
82
        $this->app->register(HtmlServiceProvider::class);
83
        $this->app->register(ExcelServiceProvider::class);
84
    }
85
86
    /**
87
     * Create aliases for the dependency.
88
     */
89
    private function registerAliases()
90
    {
91
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
92
        $loader->alias('Datatables', \Yajra\Datatables\Datatables::class);
93
    }
94
95
    /**
96
     * Get the services provided by the provider.
97
     *
98
     * @return string[]
99
     */
100
    public function provides()
101
    {
102
        return ['datatables'];
103
    }
104
}
105