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
|
|
|
* Boot the instance, add macros for datatable engines. |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function boot() |
42
|
|
|
{ |
43
|
|
|
$engines = config('datatables.engines'); |
44
|
|
|
foreach ($engines as $engine => $class) { |
45
|
|
|
$engine = camel_case($engine); |
|
|
|
|
46
|
|
|
|
47
|
|
|
if (! method_exists(DataTables::class, $engine) && ! DataTables::hasMacro($engine)) { |
48
|
|
|
DataTables::macro($engine, function () use ($class) { |
49
|
|
|
if (! call_user_func_array([$class, 'canCreate'], func_get_args())) { |
50
|
|
|
throw new \InvalidArgumentException(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return call_user_func_array([$class, 'create'], func_get_args()); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Setup package assets. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
protected function setupAssets() |
65
|
|
|
{ |
66
|
|
|
$this->mergeConfigFrom($config = __DIR__ . '/config/datatables.php', 'datatables'); |
67
|
|
|
|
68
|
|
|
if ($this->app->runningInConsole()) { |
69
|
|
|
$this->publishes([$config => config_path('datatables.php')], 'datatables'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Check if app uses Lumen. |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
protected function isLumen() |
79
|
|
|
{ |
80
|
|
|
return str_contains($this->app->version(), 'Lumen'); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.