TagServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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