Completed
Push — master ( eddec1...1fdb05 )
by Nicolas
03:17
created

BlockServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Modules\Block\Providers;
2
3
use Illuminate\Foundation\AliasLoader;
4
use Illuminate\Support\ServiceProvider;
5
use Modules\Block\Entities\Block;
6
use Modules\Block\Repositories\Cache\CacheBlockDecorator;
7
use Modules\Block\Repositories\Eloquent\EloquentBlockRepository;
8
9
class BlockServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Indicates if loading of the provider is deferred.
13
     * @var bool
14
     */
15
    protected $defer = false;
16
17
    /**
18
     * Register the service provider.
19
     * @return void
20
     */
21
    public function register()
22
    {
23
        $this->registerBindings();
24
        $this->registerFacade();
25
    }
26
27
    public function boot()
28
    {
29
        $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'asgard.block.config');
30
        $this->publishes([__DIR__ . '/../Config/config.php' => config_path('asgard.block.config' . '.php'), ], 'config');
31
    }
32
33
    /**
34
     * Get the services provided by the provider.
35
     * @return array
36
     */
37
    public function provides()
38
    {
39
        return array();
40
    }
41
42
    private function registerBindings()
43
    {
44
        $this->app->bind(
45
            'Modules\Block\Repositories\BlockRepository',
46
            function () {
47
                $repository = new EloquentBlockRepository(new Block());
48
49
                if (! config('app.cache')) {
50
                    return $repository;
51
                }
52
53
                return new CacheBlockDecorator($repository);
54
            }
55
        );
56
    }
57
58
    private function registerFacade()
59
    {
60
        $aliasLoader = AliasLoader::getInstance();
61
        $aliasLoader->alias('Block', 'Modules\Block\Facades\BlockFacade');
62
    }
63
}
64