GoAopServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2016, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Laravel\GoAopBridge;
12
13
use Go\Core\AspectContainer;
14
use Go\Core\AspectKernel;
15
use Go\Laravel\GoAopBridge\Kernel\AspectLaravelKernel;
16
use Illuminate\Support\ServiceProvider;
17
18
/**
19
 * Service provider for registration of Go! AOP framework
20
 */
21
class GoAopServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Bootstrap the application services.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        /** @var AspectContainer $aspectContainer */
31
        $aspectContainer = $this->app->make(AspectContainer::class);
32
33
        // Let's collect all aspects and just register them in the container
34
        $aspects = $this->app->tagged('goaop.aspect');
35
        foreach ($aspects as $aspect) {
36
            $aspectContainer->registerAspect($aspect);
37
        }
38
    }
39
40
    /**
41
     * Register the application services.
42
     *
43
     * @return void
44
     */
45
    public function register()
46
    {
47
        $this->publishes([$this->configPath() => config_path('go_aop.php')]);
48
        $this->mergeConfigFrom($this->configPath(), 'go_aop');
49
50
        $this->app->singleton(AspectKernel::class, function () {
51
            $aspectKernel = AspectLaravelKernel::getInstance();
52
            $aspectKernel->init(config('go_aop'));
53
54
            return $aspectKernel;
55
        });
56
57
        $this->app->singleton(AspectContainer::class, function ($app) {
58
            /** @var AspectKernel $kernel */
59
            $kernel = $app->make(AspectKernel::class);
60
61
            return $kernel->getContainer();
62
        });
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function provides()
69
    {
70
        return [AspectKernel::class, AspectContainer::class];
71
    }
72
73
    /**
74
     * Returns the path to the configuration
75
     *
76
     * @return string
77
     */
78
    private function configPath()
79
    {
80
        return __DIR__ . '/../config/go_aop.php';
81
    }
82
}
83