AppServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Providers;
4
5
use App\Repository\Admin\ConfigRepository;
6
use Illuminate\Support\Facades\App;
7
use Illuminate\Support\ServiceProvider;
8
use Schema;
9
10
class AppServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        Schema::defaultStringLength(191);
20
        if (config('light.light_config') === true && !App::environment('testing')) {
21
            $this->loadConfig();
22
        }
23
24
        /*
25
        if (\App::environment('dev')) {
26
            \DB::listen(function ($sql) {
27
                $sqlStr = $sql->sql;
28
                foreach ($sql->bindings as $replace) {
29
                    $value = is_numeric($replace) ? $replace : "'" . $replace . "'";
30
                    $sqlStr = preg_replace('/\?/', $value, $sqlStr, 1);
31
                }
32
                \Log::debug(PHP_EOL . 'SQL:' . $sqlStr . PHP_EOL . '用时:' . $sql->time . 'ms');
33
                return true;
34
            });
35
        }
36
        */
37
    }
38
39
    /**
40
     * Register any application services.
41
     *
42
     * @return void
43
     */
44
    public function register()
45
    {
46
        //
47
    }
48
49
    protected function loadConfig()
50
    {
51
        config(['light_config' => ConfigRepository::all()]);
52
        foreach (config('light_config') as $key => $value) {
53
            config(["light_config.{$key}" => parseConfig($value)]);
54
        }
55
    }
56
}
57