TagServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 7
c 5
b 0
f 0
lcom 1
cbo 8
dl 0
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A boot() 0 7 1
A provides() 0 4 1
A registerBindings() 0 16 2
A registerBladeTags() 0 9 2
1
<?php
2
3
namespace Modules\Tag\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Modules\Core\Traits\CanPublishConfiguration;
7
use Modules\Tag\Blade\TagWidget;
8
use Modules\Tag\Entities\Tag;
9
use Modules\Tag\Repositories\Cache\CacheTagDecorator;
10
use Modules\Tag\Repositories\Eloquent\EloquentTagRepository;
11
use Modules\Tag\Repositories\TagManager;
12
use Modules\Tag\Repositories\TagManagerRepository;
13
use Modules\Tag\Repositories\TagRepository;
14
15
class TagServiceProvider extends ServiceProvider
16
{
17
    use CanPublishConfiguration;
18
    /**
19
     * Indicates if loading of the provider is deferred.
20
     *
21
     * @var bool
22
     */
23
    protected $defer = false;
24
25
    /**
26
     * Register the service provider.
27
     *
28
     * @return void
29
     */
30
    public function register()
31
    {
32
        $this->registerBindings();
33
34
        $this->app->singleton('tag.widget.directive', function ($app) {
35
            return new TagWidget($app[TagRepository::class]);
36
        });
37
    }
38
39
    public function boot()
40
    {
41
        $this->publishConfig('tag', 'permissions');
42
        $this->publishConfig('tag', 'config');
43
        $this->registerBladeTags();
44
        $this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
45
    }
46
47
    /**
48
     * Get the services provided by the provider.
49
     *
50
     * @return array
51
     */
52
    public function provides()
53
    {
54
        return array();
55
    }
56
57
    private function registerBindings()
58
    {
59
        $this->app->bind(TagRepository::class, function () {
60
            $repository = new EloquentTagRepository(new Tag());
61
62
            if (! config('app.cache')) {
63
                return $repository;
64
            }
65
66
            return new CacheTagDecorator($repository);
67
        });
68
69
        $this->app->singleton(TagManager::class, function () {
70
            return new TagManagerRepository();
71
        });
72
    }
73
74
    protected function registerBladeTags()
75
    {
76
        if (app()->environment() === 'testing') {
77
            return;
78
        }
79
        $this->app['blade.compiler']->directive('tags', function ($value) {
80
            return "<?php echo TagWidget::show([$value]); ?>";
81
        });
82
    }
83
}
84