DynamicUnitServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A bootConfig() 0 5 1
A boot() 0 5 1
A bindMacroService() 0 6 2
A loadFacades() 0 3 1
1
<?php
2
3
namespace SimpleCMS\DynamicUnit;
4
5
use Illuminate\Support\ServiceProvider;
6
use SimpleCMS\Framework\Services\SimpleService;
7
use SimpleCMS\DynamicUnit\Services\DynamicAttributeService;
8
9
class DynamicUnitServiceProvider extends ServiceProvider
10
{
11
12
    /**
13
     * Bootstrap services.
14
     */
15
    public function boot(): void
16
    {
17
        $this->bootConfig();
18
        $this->loadFacades();
19
        $this->bindMacroService();
20
    }
21
22
    /**
23
     * 修改query
24
     *
25
     * @author Dennis Lui <[email protected]>
26
     * @return void
27
     */
28
    protected function bindMacroService(): void
29
    {
30
        if (class_exists(SimpleService::class)) {
31
            SimpleService::macro('queryAttribute', function (SimpleService $service, array $parameters) {
32
                $attributeService = new DynamicAttributeService;
33
                return $attributeService->queryAttribute($service,$parameters);
34
            });
35
        }
36
    }
37
38
    /**
39
     * 绑定Facades
40
     *
41
     * @author Dennis Lui <[email protected]>
42
     * @return void
43
     */
44
    protected function loadFacades(): void
45
    {
46
        $this->app->bind('dynamic_unit', fn() => new \SimpleCMS\DynamicUnit\Packages\DynamicUnit);
47
    }
48
49
    /**
50
     * 初始化配置文件
51
     * @return void
52
     */
53
    protected function bootConfig(): void
54
    {
55
        $this->publishes([
56
            __DIR__ . '/../database/migrations' => database_path('migrations'),
57
        ], 'simplecms');
58
    }
59
}
60