BlockServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Modules\Block\Providers;
4
5
use Illuminate\Foundation\AliasLoader;
6
use Illuminate\Support\ServiceProvider;
7
use Modules\Core\Events\LoadingBackendTranslations;
8
use Modules\Block\Entities\Block;
9
use Modules\Block\Events\Handlers\RegisterBlockSidebar;
10
use Modules\Block\Facades\BlockFacade;
11
use Modules\Block\Repositories\Cache\CacheBlockDecorator;
12
use Modules\Block\Repositories\Eloquent\EloquentBlockRepository;
13
use Modules\Core\Events\BuildingSidebar;
14
use Modules\Core\Traits\CanGetSidebarClassForModule;
15
use Modules\Core\Traits\CanPublishConfiguration;
16
17
class BlockServiceProvider extends ServiceProvider
18
{
19
    use CanPublishConfiguration, CanGetSidebarClassForModule;
20
    /**
21
     * Indicates if loading of the provider is deferred.
22
     * @var bool
23
     */
24
    protected $defer = false;
25
26
    /**
27
     * Register the service provider.
28
     * @return void
29
     */
30
    public function register()
31
    {
32
        $this->registerBindings();
33
        $this->registerFacade();
34
35
        $this->app['events']->listen(
36
            BuildingSidebar::class,
37
            $this->getSidebarClassForModule('block', RegisterBlockSidebar::class)
38
        );
39
40
        $this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
41
            $event->load('blocks', array_dot(trans('block::blocks')));
42
        });
43
    }
44
45
    public function boot()
46
    {
47
        $this->publishConfig('block', 'permissions');
48
        $this->publishConfig('block', 'config');
49
        $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
50
    }
51
52
    /**
53
     * Get the services provided by the provider.
54
     * @return array
55
     */
56
    public function provides()
57
    {
58
        return array();
59
    }
60
61
    private function registerBindings()
62
    {
63
        $this->app->bind(
64
            'Modules\Block\Repositories\BlockRepository',
65
            function () {
66
                $repository = new EloquentBlockRepository(new Block());
67
68
                if (! config('app.cache')) {
69
                    return $repository;
70
                }
71
72
                return new CacheBlockDecorator($repository);
73
            }
74
        );
75
    }
76
77
    private function registerFacade()
78
    {
79
        $aliasLoader = AliasLoader::getInstance();
80
        $aliasLoader->alias('Block', BlockFacade::class);
81
    }
82
}
83