|
1
|
|
|
<?php namespace Modules\Blog\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Routing\Router; |
|
4
|
|
|
use Illuminate\Support\Facades\Config; |
|
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\Eloquent\EloquentCategoryRepository; |
|
13
|
|
|
use Modules\Blog\Repositories\Eloquent\EloquentPostRepository; |
|
14
|
|
|
use Modules\Blog\Repositories\Eloquent\EloquentTagRepository; |
|
15
|
|
|
|
|
16
|
|
|
class BlogServiceProvider extends ServiceProvider |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Indicates if loading of the provider is deferred. |
|
20
|
|
|
* |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $defer = false; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The filters base class name. |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $filters = [ |
|
31
|
|
|
'Core' => [ |
|
32
|
|
|
'permissions' => 'PermissionFilter', |
|
33
|
|
|
'auth.admin' => 'AdminFilter', |
|
34
|
|
|
], |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register the service provider. |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function register() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->registerFilters($this->app['router']); |
|
45
|
|
|
$this->registerBindings(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Register the filters. |
|
50
|
|
|
* |
|
51
|
|
|
* @param Router $router |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
public function registerFilters(Router $router) |
|
55
|
|
|
{ |
|
56
|
|
|
foreach ($this->filters as $module => $filters) { |
|
57
|
|
|
foreach ($filters as $name => $filter) { |
|
58
|
|
|
$class = "Modules\\{$module}\\Http\\Filters\\{$filter}"; |
|
59
|
|
|
|
|
60
|
|
|
$router->filter($name, $class); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the services provided by the provider. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function provides() |
|
71
|
|
|
{ |
|
72
|
|
|
return array(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function registerBindings() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->app->bind( |
|
78
|
|
|
'Modules\Blog\Repositories\PostRepository', |
|
79
|
|
|
function () { |
|
80
|
|
|
$repository = new EloquentPostRepository(new Post()); |
|
81
|
|
|
|
|
82
|
|
|
if (! Config::get('app.cache')) { |
|
83
|
|
|
return $repository; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return new CachePostDecorator($repository); |
|
87
|
|
|
} |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$this->app->bind( |
|
91
|
|
|
'Modules\Blog\Repositories\CategoryRepository', |
|
92
|
|
|
function () { |
|
93
|
|
|
$repository = new EloquentCategoryRepository(new Category()); |
|
94
|
|
|
|
|
95
|
|
|
if (! Config::get('app.cache')) { |
|
96
|
|
|
return $repository; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return new CacheCategoryDecorator($repository); |
|
100
|
|
|
} |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$this->app->bind( |
|
104
|
|
|
'Modules\Blog\Repositories\TagRepository', |
|
105
|
|
|
function () { |
|
106
|
|
|
$repository = new EloquentTagRepository(new Tag()); |
|
107
|
|
|
|
|
108
|
|
|
if (! Config::get('app.cache')) { |
|
109
|
|
|
return $repository; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return new CacheTagDecorator($repository); |
|
113
|
|
|
} |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|