1
|
|
|
<?php namespace jlourenco\blog; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\ServiceProvider; |
4
|
|
|
use jlourenco\blog\Repositories\BlogCategoryRepository; |
5
|
|
|
use jlourenco\blog\Repositories\BlogPostRepository; |
6
|
|
|
|
7
|
|
|
class blogServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Perform post-registration booting of services. |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
|
|
public function boot() |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Register any package services. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public function register() |
26
|
|
|
{ |
27
|
|
|
$this->prepareResources(); |
28
|
|
|
$this->registerBlogCategory(); |
29
|
|
|
$this->registerBlogPost(); |
30
|
|
|
$this->registerBlog(); |
31
|
|
|
$this->registerToAppConfig(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Prepare the package resources. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function prepareResources() |
40
|
|
|
{ |
41
|
|
|
// Publish our views |
42
|
|
|
$this->loadViewsFrom(base_path("resources/views"), 'base'); |
43
|
|
|
$this->publishes([ |
44
|
|
|
__DIR__ . '/views' => base_path("resources/views") |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
// Publish our lang |
48
|
|
|
$this->publishes([ |
49
|
|
|
__DIR__ . '/lang' => base_path("resources/lang") |
50
|
|
|
], 'migrations'); |
51
|
|
|
|
52
|
|
|
// Publish our migrations |
53
|
|
|
$this->publishes([ |
54
|
|
|
__DIR__ . '/migrations' => base_path("database/migrations") |
55
|
|
|
], 'migrations'); |
56
|
|
|
|
57
|
|
|
// Publish a config file |
58
|
|
|
$this->publishes([ |
59
|
|
|
__DIR__ . '/config' => base_path('/config') |
60
|
|
|
], 'config'); |
61
|
|
|
|
62
|
|
|
// Publish our routes |
63
|
|
|
$this->publishes([ |
64
|
|
|
__DIR__ . '/routes.php' => base_path("app/Http/blog_routes.php") |
65
|
|
|
], 'routes'); |
66
|
|
|
|
67
|
|
|
// Include the routes file |
68
|
|
|
if(file_exists(base_path("app/Http/blog_routes.php"))) |
69
|
|
|
include base_path("app/Http/blog_routes.php"); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Registers the blog posts. |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
protected function registerBlogPost() |
78
|
|
|
{ |
79
|
|
|
$this->app->singleton('jlourenco.blog.post', function ($app) { |
80
|
|
|
$baseConfig = $app['config']->get('jlourenco.base'); |
81
|
|
|
$config = $app['config']->get('jlourenco.blog'); |
82
|
|
|
|
83
|
|
|
$model = array_get($config, 'models.BlogPost'); |
84
|
|
|
$users = array_get($baseConfig, 'models.User'); |
85
|
|
|
$categories = array_get($config, 'models.BlogCategory'); |
86
|
|
|
|
87
|
|
|
if (class_exists($model) && method_exists($model, 'setUsersModel')) |
88
|
|
|
forward_static_call_array([$model, 'setUsersModel'], [$users]); |
89
|
|
|
|
90
|
|
|
if (class_exists($model) && method_exists($model, 'setCategoriesModel')) |
91
|
|
|
forward_static_call_array([$model, 'setCategoriesModel'], [$categories]); |
92
|
|
|
|
93
|
|
|
return new BlogPostRepository($model); |
94
|
|
|
}); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Registers the blog posts. |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
protected function registerBlogCategory() |
103
|
|
|
{ |
104
|
|
|
$this->app->singleton('jlourenco.blog.category', function ($app) { |
105
|
|
|
$config = $app['config']->get('jlourenco.blog'); |
106
|
|
|
|
107
|
|
|
$model = array_get($config, 'models.BlogCategory'); |
108
|
|
|
$posts = array_get($config, 'models.BlogPost'); |
109
|
|
|
|
110
|
|
|
if (class_exists($model) && method_exists($model, 'setPostsModel')) |
111
|
|
|
forward_static_call_array([$model, 'setPostsModel'], [$posts]); |
112
|
|
|
|
113
|
|
|
return new BlogCategoryRepository($model); |
114
|
|
|
}); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Registers log. |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
protected function registerBlog() |
123
|
|
|
{ |
124
|
|
|
$this->app->singleton('blog', function ($app) { |
125
|
|
|
$blog = new Blog($app['jlourenco.blog.post'], $app['jlourenco.blog.category']); |
126
|
|
|
|
127
|
|
|
return $blog; |
128
|
|
|
}); |
129
|
|
|
|
130
|
|
|
$this->app->alias('blog', 'jlourenco\blog\Blog'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Registers this module to the |
135
|
|
|
* services providers and aliases. |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
protected function registerToAppConfig() |
140
|
|
|
{ |
141
|
|
|
/* |
142
|
|
|
* Create aliases for the dependencies. |
143
|
|
|
*/ |
144
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
145
|
|
|
$loader->alias('Blog', 'jlourenco\blog\Facades\Blog'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* {@inheritDoc} |
150
|
|
|
*/ |
151
|
|
|
public function provides() |
152
|
|
|
{ |
153
|
|
|
return [ |
154
|
|
|
'jlourenco.blog.post', |
155
|
|
|
'jlourenco.blog.category', |
156
|
|
|
'blog' |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
} |