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