AppServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 44
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 3
A register() 0 2 1
A loadConfig() 0 5 2
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