Completed
Push — master ( 525fa2...dc2210 )
by Nils
02:11
created

DatatableServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4286
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace OpenSkill\Datatable;
4
5
use App;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\ServiceProvider;
8
use OpenSkill\Datatable\Versions\Datatable19Version;
9
use OpenSkill\Datatable\Versions\VersionEngine;
10
use Symfony\Component\HttpFoundation\RequestStack;
11
12
class DatatableServiceProvider extends ServiceProvider
13
{
14
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = true;
21
22
    /**
23
     * Register the application services.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        /** @var RequestStack $requestStack */
30
        $requestStack = $this->app->make('Symfony\Component\HttpFoundation\RequestStack');
31
        if ($requestStack->getCurrentRequest() == null) {
32
            $requestStack->push($this->app->make('request'));
33
        }
34
35
        $this->app->singleton("datatable", function (Application $app) use ($requestStack) {
36
            $dt = new Datatable19Version($requestStack);
37
            return new Datatable(
38
                new VersionEngine([$dt], $dt),
39
                $app->make('Illuminate\Contracts\View\Factory'),
40
                $app->make('Illuminate\Contracts\Config\Repository')
41
            );
42
        });
43
    }
44
45
    /**
46
     * Get the services provided by the provider.
47
     *
48
     * @return array
49
     */
50
    public function provides()
51
    {
52
        return [
53
            'datatable',
54
        ];
55
    }
56
57
    /**
58
     * Perform post-registration booting of services.
59
     *
60
     * @return void
61
     */
62
    public function boot()
63
    {
64
        // load views
65
        $this->loadViewsFrom(__DIR__.'/../../views', 'datatable');
66
67
        // publish views if the user wants to
68
        $this->publishes([
69
            __DIR__.'/../../views' => base_path('resources/views/vendor/datatable'),
70
        ]);
71
72
        $this->mergeConfigFrom(
73
            __DIR__.'/../../config/datatable.php', 'datatable'
74
        );
75
76
        // publish the configs if the user wants to
77
        $this->publishes([
78
            __DIR__.'/../../config/datatable.php' => config_path('datatable.php'),
79
        ]);
80
    }
81
82
83
}
84