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

DataTablesServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 19 2
A setupAssets() 0 8 2
A isLumen() 0 4 1
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