1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Blog\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Modules\Blog\Entities\Category; |
7
|
|
|
use Modules\Blog\Entities\Post; |
8
|
|
|
use Modules\Blog\Entities\Tag; |
9
|
|
|
use Modules\Blog\Events\Handlers\RegisterBlogSidebar; |
10
|
|
|
use Modules\Blog\Repositories\Cache\CacheCategoryDecorator; |
11
|
|
|
use Modules\Blog\Repositories\Cache\CachePostDecorator; |
12
|
|
|
use Modules\Blog\Repositories\Cache\CacheTagDecorator; |
13
|
|
|
use Modules\Blog\Repositories\CategoryRepository; |
14
|
|
|
use Modules\Blog\Repositories\Eloquent\EloquentCategoryRepository; |
15
|
|
|
use Modules\Blog\Repositories\Eloquent\EloquentPostRepository; |
16
|
|
|
use Modules\Blog\Repositories\Eloquent\EloquentTagRepository; |
17
|
|
|
use Modules\Blog\Repositories\PostRepository; |
18
|
|
|
use Modules\Blog\Repositories\TagRepository; |
19
|
|
|
use Modules\Core\Events\BuildingSidebar; |
20
|
|
|
use Modules\Core\Traits\CanGetSidebarClassForModule; |
21
|
|
|
use Modules\Core\Traits\CanPublishConfiguration; |
22
|
|
|
use Modules\Media\Image\ThumbnailManager; |
23
|
|
|
|
24
|
|
|
class BlogServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
use CanPublishConfiguration, CanGetSidebarClassForModule; |
27
|
|
|
/** |
28
|
|
|
* Indicates if loading of the provider is deferred. |
29
|
|
|
* |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $defer = false; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Register the service provider. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
10 |
|
public function register() |
40
|
|
|
{ |
41
|
10 |
|
$this->registerBindings(); |
42
|
|
|
|
43
|
10 |
|
$this->app['events']->listen( |
44
|
10 |
|
BuildingSidebar::class, |
45
|
10 |
|
$this->getSidebarClassForModule('blog', RegisterBlogSidebar::class) |
46
|
10 |
|
); |
47
|
10 |
|
} |
48
|
|
|
|
49
|
10 |
|
public function boot() |
50
|
|
|
{ |
51
|
10 |
|
$this->publishes([ |
52
|
10 |
|
__DIR__ . '/../Resources/views' => base_path('resources/views/asgard/blog'), |
53
|
10 |
|
]); |
54
|
|
|
|
55
|
10 |
|
$this->publishConfig('blog', 'config'); |
56
|
10 |
|
$this->publishConfig('blog', 'permissions'); |
57
|
10 |
|
$this->publishConfig('blog', 'settings'); |
58
|
10 |
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); |
59
|
|
|
|
60
|
10 |
|
$this->registerThumbnails(); |
61
|
10 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the services provided by the provider. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function provides() |
69
|
|
|
{ |
70
|
|
|
return array(); |
71
|
|
|
} |
72
|
|
|
|
73
|
10 |
|
private function registerBindings() |
74
|
|
|
{ |
75
|
|
|
$this->app->bind(PostRepository::class, function () { |
76
|
10 |
|
$repository = new EloquentPostRepository(new Post()); |
77
|
|
|
|
78
|
10 |
|
if (config('app.cache') === false) { |
79
|
|
|
return $repository; |
80
|
|
|
} |
81
|
|
|
|
82
|
10 |
|
return new CachePostDecorator($repository); |
83
|
10 |
|
}); |
84
|
|
|
|
85
|
|
|
$this->app->bind(CategoryRepository::class, function () { |
86
|
|
|
$repository = new EloquentCategoryRepository(new Category()); |
87
|
|
|
|
88
|
|
|
if (config('app.cache') === false) { |
89
|
|
|
return $repository; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return new CacheCategoryDecorator($repository); |
93
|
10 |
|
}); |
94
|
|
|
|
95
|
|
|
$this->app->bind(TagRepository::class, function () { |
96
|
10 |
|
$repository = new EloquentTagRepository(new Tag()); |
97
|
|
|
|
98
|
10 |
|
if (config('app.cache') === false) { |
99
|
|
|
return $repository; |
100
|
|
|
} |
101
|
|
|
|
102
|
10 |
|
return new CacheTagDecorator($repository); |
103
|
10 |
|
}); |
104
|
10 |
|
} |
105
|
|
|
|
106
|
10 |
|
private function registerThumbnails() |
107
|
|
|
{ |
108
|
10 |
|
$this->app[ThumbnailManager::class]->registerThumbnail('blogThumb', [ |
109
|
|
|
'fit' => [ |
110
|
10 |
|
'width' => '150', |
111
|
10 |
|
'height' => '150', |
112
|
10 |
|
'callback' => function ($constraint) { |
113
|
|
|
$constraint->upsize(); |
114
|
10 |
|
}, |
115
|
10 |
|
], |
116
|
10 |
|
]); |
117
|
10 |
|
} |
118
|
|
|
} |
119
|
|
|
|