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
|
|
|
if ($this->isLumen()) { |
69
|
|
|
require_once 'fallback.php'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->registerRequiredProviders(); |
73
|
|
|
|
74
|
|
|
$this->app->singleton('datatables', function ($app) { |
75
|
|
|
return new Datatables($app->make(Request::class)); |
76
|
|
|
}); |
77
|
|
|
|
78
|
|
|
$this->registerAliases(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Check if app uses Lumen. |
83
|
|
|
* |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
private function isLumen() |
87
|
|
|
{ |
88
|
|
|
return str_contains($this->app->version(), 'Lumen'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Register 3rd party providers. |
93
|
|
|
*/ |
94
|
|
|
private function registerRequiredProviders() |
95
|
|
|
{ |
96
|
|
|
$this->app->register(HtmlServiceProvider::class); |
97
|
|
|
$this->app->register(ExcelServiceProvider::class); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Create aliases for the dependency. |
102
|
|
|
*/ |
103
|
|
|
private function registerAliases() |
104
|
|
|
{ |
105
|
|
|
if (class_exists('Illuminate\Foundation\AliasLoader')) { |
106
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
107
|
|
|
$loader->alias('Datatables', \Yajra\Datatables\Datatables::class); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the services provided by the provider. |
113
|
|
|
* |
114
|
|
|
* @return string[] |
115
|
|
|
*/ |
116
|
|
|
public function provides() |
117
|
|
|
{ |
118
|
|
|
return ['datatables']; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|