DataTablesServiceProvider::mergeConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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 14
    public function register()
15
    {
16 14
        $this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class);
17 14
        $this->app->register(\Yajra\DataTables\ButtonsServiceProvider::class);
18
19 14
        $this->replaceBindings();
20
21 14
        $this->configureDataTables();
22 14
    }
23
24
    /**
25
     * Replace the original DataTables bindings.
26
     *
27
     * @return void
28
     */
29 14
    protected function replaceBindings()
30
    {
31 14
        $this->app->alias('datatables', DataTables::class);
32 14
        $this->app->singleton('datatables', function () {
33 8
            return new DataTables;
34 14
        });
35
36 14
        $this->app->bind('datatables.html', Html\Builder::class);
37 14
    }
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 14
    protected function configureDataTables()
48
    {
49 14
        $this->mergeConfig('datatables.builders', [
50 14
            \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 14
        $this->mergeConfig('datatables-buttons', [
57 14
            'stub' => '/vendor/elfsundae/laravel-datatables/src/stubs',
58
        ]);
59 14
    }
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 14
    protected function mergeConfig($key, array $config)
69
    {
70 14
        $current = $this->app['config']->get($key, []);
71
72 14
        $this->app['config']->set($key, array_merge($config, $current));
73 14
    }
74
}
75