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