Completed
Push — master ( a97a17...501027 )
by Arjay
02:05
created

src/DataTablesServiceProvider.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
0 ignored issues
show
Deprecated Code introduced by
The function camel_case() has been deprecated with message: Str::camel() should be used directly instead. Will be removed in Laravel 5.9.

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.

Loading history...
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');
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

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.

Loading history...
81
    }
82
}
83