1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FaithGen\SDK; |
4
|
|
|
|
5
|
|
|
use FaithGen\SDK\Http\Middleware\ActivatedMinistryMiddleware; |
6
|
|
|
use FaithGen\SDK\Http\Middleware\SourceSiteMiddleware; |
7
|
|
|
use FaithGen\SDK\Mixins\DatabaseBuilder; |
8
|
|
|
use FaithGen\SDK\Services\ImageService; |
9
|
|
|
use FaithGen\SDK\Services\ProfileService; |
10
|
|
|
use FaithGen\SDK\Traits\ConfigTrait; |
11
|
|
|
use Illuminate\Database\Query\Builder; |
12
|
|
|
use Illuminate\Support\Facades\Route; |
13
|
|
|
use Illuminate\Support\ServiceProvider; |
14
|
|
|
|
15
|
|
|
class FaithGenSDKServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
use ConfigTrait; |
18
|
|
|
|
19
|
|
|
public function boot() |
20
|
|
|
{ |
21
|
|
|
$this->registerApiRoutes(); |
22
|
|
|
$this->registerParentRoutes(); |
23
|
|
|
$this->registerUserAuthRoutes(); |
24
|
|
|
|
25
|
|
|
if ($this->app->runningInConsole()) { |
26
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
27
|
|
|
|
28
|
|
|
$this->publishes([ |
29
|
|
|
__DIR__.'/../config/faithgen-sdk.php' => config_path('faithgen-sdk.php'), |
30
|
|
|
], 'faithgen-sdk-config'); |
31
|
|
|
|
32
|
|
|
$this->setUpSourceFiles(function () { |
33
|
|
|
$this->publishes([ |
34
|
|
|
__DIR__.'/../database/migrations/' => database_path('migrations'), |
35
|
|
|
], 'faithgen-sdk-migrations'); |
36
|
|
|
|
37
|
|
|
$this->publishes([ |
38
|
|
|
__DIR__.'/../storage/profile/' => storage_path('app/public/profile'), |
39
|
|
|
], 'faithgen-sdk-storage'); |
40
|
|
|
|
41
|
|
|
$this->loadFactoriesFrom(__DIR__.'/../database/factories'); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
if (! config('faithgen-sdk.source')) { |
45
|
|
|
$this->publishes([ |
46
|
|
|
__DIR__.'/../storage/users/' => storage_path('app/public/users'), |
47
|
|
|
], 'faithgen-sdk-storage'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->publishes([ |
51
|
|
|
__DIR__.'/../storage/logo/' => public_path('images'), |
52
|
|
|
], 'faithgen-logo'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
app('router')->aliasMiddleware('ministry.activated', ActivatedMinistryMiddleware::class); |
56
|
|
|
app('router')->aliasMiddleware('source.site', SourceSiteMiddleware::class); |
57
|
|
|
|
58
|
|
|
Builder::mixin(new DatabaseBuilder(), true); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function apiRouteConfiguration() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'prefix' => config('faithgen-sdk.prefix'), |
65
|
|
|
'middleware' => [ |
66
|
|
|
'auth:api', |
67
|
|
|
'ministry.activated', |
68
|
|
|
'bindings', |
69
|
|
|
], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function registerApiRoutes() |
74
|
|
|
{ |
75
|
|
|
Route::group($this->apiRouteConfiguration(), function () { |
76
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/api.php'); |
77
|
|
|
}); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function parentRouteConfiguration() |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
'prefix' => config('faithgen-sdk.prefix'), |
84
|
|
|
'middleware' => [ |
85
|
|
|
'auth:api', |
86
|
|
|
'ministry.activated', |
87
|
|
|
'source.site', |
88
|
|
|
'bindings', |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function registerParentRoutes() |
94
|
|
|
{ |
95
|
|
|
if (config('faithgen-sdk.source')) { |
96
|
|
|
Route::group($this->parentRouteConfiguration(), function () { |
97
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/source.php'); |
98
|
|
|
}); |
99
|
|
|
|
100
|
|
|
$this->registerAuthRoutes(); |
101
|
|
|
|
102
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/web.php'); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function authRouteConfiguration() |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
'prefix' => config('faithgen-sdk.prefix'), |
110
|
|
|
'middleware' => ['bindings'], |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function registerAuthRoutes() |
115
|
|
|
{ |
116
|
|
|
Route::group($this->authRouteConfiguration(), function () { |
117
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/auth.php'); |
118
|
|
|
}); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
private function registerUserAuthRoutes() |
122
|
|
|
{ |
123
|
|
|
Route::group($this->authRouteConfiguration(), function () { |
124
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/users-auth.php'); |
125
|
|
|
}); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Register services. |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
public function register() |
134
|
|
|
{ |
135
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/faithgen-sdk.php', 'faithgen-sdk'); |
136
|
|
|
|
137
|
|
|
$this->app->singleton(ProfileService::class); |
138
|
|
|
$this->app->singleton(ImageService::class); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritdoc} |
143
|
|
|
*/ |
144
|
|
|
public function routeConfiguration(): array |
145
|
|
|
{ |
146
|
|
|
// TODO: Implement routeConfiguration() method. |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|