Completed
Push — master ( 67a4ad...dccd42 )
by Elf
03:40 queued 02:13
created

DataTablesServiceProvider::replaceBindings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ElfSundae\DataTables;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class DataTablesServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Register the service provider.
11
     *
12
     * @return void
13
     */
14 7
    public function register()
15
    {
16 7
        $this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class);
17 7
        $this->app->register(\Yajra\DataTables\ButtonsServiceProvider::class);
18
19 7
        $this->replaceBindings();
20
21 7
        $this->configureDataTables();
22 7
    }
23
24
    /**
25
     * Replace the original DataTables bindings.
26
     *
27
     * @return void
28
     */
29 7
    protected function replaceBindings()
30
    {
31 7
        $this->app->alias('datatables', DataTables::class);
32 7
        $this->app->singleton('datatables', function () {
33 4
            return new DataTables;
34 7
        });
35
36 7
        $this->app->bind('datatables.html', Html\Builder::class);
37 7
    }
38
39
    /**
40
     * Configure DataTables.
41
     *
42
     * - Restore the default "builders" configuration, see https://github.com/yajra/laravel-datatables/pull/1462/commits/afdbe6bce9ade9b19d66034ace3d8a2c24da8a56
43
     * - Configure our custom DataTable service stub for "datatables:make" command
44
     *
45
     * @return void
46
     */
47 7
    protected function configureDataTables()
48
    {
49 7
        $this->mergeConfig('datatables.builders', [
50 7
            \Illuminate\Database\Eloquent\Builder::class => 'eloquent',
51
            \Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent',
52
            \Illuminate\Database\Query\Builder::class => 'query',
53
            \Illuminate\Support\Collection::class => 'collection',
54
        ]);
55
56 7
        $this->mergeConfig('datatables-buttons', [
57 7
            'stub' => '/vendor/elfsundae/laravel-datatables/src/stubs',
58
        ]);
59 7
    }
60
61
    /**
62
     * Merge the given configuration with the existing configuration.
63
     *
64
     * @param  string  $key
65
     * @param  array  $config
66
     * @return void
67
     */
68 7
    protected function mergeConfig($key, array $config)
69
    {
70 7
        $current = $this->app['config']->get($key, []);
71
72 7
        $this->app['config']->set($key, array_merge($config, $current));
73 7
    }
74
}
75