AspectServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 25 1
A provides() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 *
13
 * This software consists of voluntary contributions made by many individuals
14
 * and is licensed under the MIT license.
15
 *
16
 * Copyright (c) 2015-2020 Yuuki Takezawa
17
 *
18
 */
19
20
namespace Ytake\LaravelAspect;
21
22
use Illuminate\Support\ServiceProvider;
23
24
/**
25
 * Class AspectServiceProvider
26
 */
27
class AspectServiceProvider extends ServiceProvider
28
{
29
    /** @var bool */
30
    protected $defer = false;
31
32
    /**
33
     * boot aspect kernel
34
     */
35
    public function boot(): void
36
    {
37
        $this->app['aspect.manager']->weave();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function register(): void
44
    {
45
        /**
46
         * for package configure
47
         */
48
        $configPath = __DIR__ . '/config/ytake-laravel-aop.php';
49
        $this->mergeConfigFrom($configPath, 'ytake-laravel-aop');
50
        $this->publishes([$configPath => config_path('ytake-laravel-aop.php')], 'aspect');
51
52
        $this->app->singleton(AnnotationConfiguration::class, function ($app) {
53
            $annotationConfiguration = new AnnotationConfiguration(
54
                $app['config']->get('ytake-laravel-aop.annotation')
55
            );
56
57
            return $annotationConfiguration;
58
        });
59
        $this->app->singleton('aspect.manager', function ($app) {
60
            /** @var AnnotationConfiguration $annotationConfiguration */
61
            $annotationConfiguration = $app->make(AnnotationConfiguration::class);
62
            $annotationConfiguration->ignoredAnnotations();
63
64
            // register annotation
65
            return new AspectManager($app);
66
        });
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function provides()
73
    {
74
        return [
75
            'aspect.manager',
76
        ];
77
    }
78
}
79