Completed
Push — master ( 93a343...4c54b3 )
by Nicolas
07:23
created

BlogServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Modules\Blog\Providers;
2
3
use Illuminate\Support\ServiceProvider;
4
use Modules\Blog\Entities\Category;
5
use Modules\Blog\Entities\Post;
6
use Modules\Blog\Entities\Tag;
7
use Modules\Blog\Repositories\Cache\CacheCategoryDecorator;
8
use Modules\Blog\Repositories\Cache\CachePostDecorator;
9
use Modules\Blog\Repositories\Cache\CacheTagDecorator;
10
use Modules\Blog\Repositories\CategoryRepository;
11
use Modules\Blog\Repositories\Eloquent\EloquentCategoryRepository;
12
use Modules\Blog\Repositories\Eloquent\EloquentPostRepository;
13
use Modules\Blog\Repositories\Eloquent\EloquentTagRepository;
14
use Modules\Blog\Repositories\PostRepository;
15
use Modules\Blog\Repositories\TagRepository;
16
17
class BlogServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * Indicates if loading of the provider is deferred.
21
     *
22
     * @var bool
23
     */
24
    protected $defer = false;
25
26
    /**
27
     * Register the service provider.
28
     *
29
     * @return void
30
     */
31
    public function register()
32
    {
33
        $this->registerBindings();
34
    }
35
36
    public function boot()
37
    {
38
        $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'asgard.blog.config');
39
        $this->publishes([__DIR__ . '/../Config/config.php' => config_path('asgard.blog.config' . '.php'), ], 'config');
40
    }
41
42
    /**
43
     * Get the services provided by the provider.
44
     *
45
     * @return array
46
     */
47
    public function provides()
48
    {
49
        return array();
50
    }
51
52
    private function registerBindings()
53
    {
54
        $this->app->bind(PostRepository::class, function () {
55
                $repository = new EloquentPostRepository(new Post());
56
57
                if (config('app.cache') === false) {
58
                    return $repository;
59
                }
60
61
                return new CachePostDecorator($repository);
62
            }
63
        );
64
65
        $this->app->bind(CategoryRepository::class, function () {
66
                $repository = new EloquentCategoryRepository(new Category());
67
68
                if (config('app.cache') === false) {
69
                    return $repository;
70
                }
71
72
                return new CacheCategoryDecorator($repository);
73
            }
74
        );
75
76
        $this->app->bind(TagRepository::class, function () {
77
                $repository = new EloquentTagRepository(new Tag());
78
79
                if (config('app.cache') === false) {
80
                    return $repository;
81
                }
82
83
                return new CacheTagDecorator($repository);
84
            }
85
        );
86
    }
87
}
88