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

BlockServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 6
c 3
b 0
f 1
lcom 1
cbo 6
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A boot() 0 5 1
A provides() 0 4 1
A registerBindings() 0 15 2
A registerFacade() 0 5 1
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