Completed
Pull Request — master (#1488)
by Elf
01:39
created

DataTablesServiceProvider::boot()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
nc 3
nop 0
dl 0
loc 17
rs 8.8571
c 1
b 0
f 0
1
<?php
2
3
namespace Yajra\DataTables;
4
5
use Yajra\DataTables\Utilities\Config;
6
use Illuminate\Support\ServiceProvider;
7
use Yajra\DataTables\Utilities\Request;
8
9
class DataTablesServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the service provider.
13
     *
14
     * @return void
15
     */
16
    public function register()
17
    {
18
        if ($this->isLumen()) {
19
            require_once 'lumen.php';
20
        }
21
22
        $this->setupAssets();
23
24
        $this->app->alias('datatables', DataTables::class);
25
        $this->app->singleton('datatables', function () {
26
            return new DataTables;
27
        });
28
29
        $this->app->singleton('datatables.request', function () {
30
            return new Request;
31
        });
32
33
        $this->app->singleton('datatables.config', Config::class);
34
    }
35
36
    /**
37
     * Setup package assets.
38
     *
39
     * @return void
40
     */
41
    protected function setupAssets()
42
    {
43
        $this->mergeConfigFrom($config = __DIR__ . '/config/datatables.php', 'datatables');
44
45
        if ($this->app->runningInConsole()) {
46
            $this->publishes([$config => config_path('datatables.php')], 'datatables');
47
        }
48
    }
49
50
    /**
51
     * Check if app uses Lumen.
52
     *
53
     * @return bool
54
     */
55
    protected function isLumen()
56
    {
57
        return str_contains($this->app->version(), 'Lumen');
58
    }
59
}
60