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