1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Fort\Providers; |
6
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Rinvex\Fort\Models\Role; |
9
|
|
|
use Rinvex\Fort\Models\User; |
10
|
|
|
use Illuminate\Routing\Router; |
11
|
|
|
use Rinvex\Menus\Facades\Menu; |
12
|
|
|
use Rinvex\Fort\Models\Ability; |
13
|
|
|
use Rinvex\Fort\Models\Session; |
14
|
|
|
use Illuminate\Support\ServiceProvider; |
15
|
|
|
use Rinvex\Menus\Factories\MenuFactory; |
16
|
|
|
use Cortex\Fort\Console\Commands\SeedCommand; |
17
|
|
|
use Cortex\Fort\Console\Commands\InstallCommand; |
18
|
|
|
use Cortex\Fort\Console\Commands\MigrateCommand; |
19
|
|
|
use Cortex\Fort\Console\Commands\PublishCommand; |
20
|
|
|
use Cortex\Fort\Console\Commands\RollbackCommand; |
21
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation; |
22
|
|
|
|
23
|
|
|
class FortServiceProvider extends ServiceProvider |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The commands to be registered. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $commands = [ |
31
|
|
|
SeedCommand::class => 'command.cortex.fort.seed', |
32
|
|
|
InstallCommand::class => 'command.cortex.fort.install', |
33
|
|
|
MigrateCommand::class => 'command.cortex.fort.migrate', |
34
|
|
|
PublishCommand::class => 'command.cortex.fort.publish', |
35
|
|
|
RollbackCommand::class => 'command.cortex.fort.rollback', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Register any application services. |
40
|
|
|
* |
41
|
|
|
* This service provider is a great spot to register your various container |
42
|
|
|
* bindings with the application. As you can see, we are registering our |
43
|
|
|
* "Registrar" implementation here. You can add your own bindings too! |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function register(): void |
48
|
|
|
{ |
49
|
|
|
$this->app->singleton('cortex.fort.user.tabs', function ($app) { |
|
|
|
|
50
|
|
|
return collect(); |
51
|
|
|
}); |
52
|
|
|
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'cortex.fort'); |
53
|
|
|
|
54
|
|
|
// Register console commands |
55
|
|
|
! $this->app->runningInConsole() || $this->registerCommands(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Bootstrap any application services. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function boot(Router $router): void |
64
|
|
|
{ |
65
|
|
|
// Attach request macro |
66
|
|
|
$this->attachRequestMacro(); |
67
|
|
|
|
68
|
|
|
// Bind route models and constrains |
69
|
|
|
$router->pattern('ability', '[0-9]+'); |
70
|
|
|
$router->pattern('role', '[a-z0-9-]+'); |
71
|
|
|
$router->pattern('user', '[a-zA-Z0-9_-]+'); |
72
|
|
|
$router->pattern('session', '[a-zA-Z0-9]+'); |
73
|
|
|
$router->model('ability', Ability::class); |
74
|
|
|
$router->model('session', Session::class); |
75
|
|
|
$router->model('role', Role::class); |
76
|
|
|
$router->model('user', User::class); |
77
|
|
|
|
78
|
|
|
// Map relations |
79
|
|
|
Relation::morphMap([ |
80
|
|
|
'role' => config('rinvex.fort.models.role'), |
81
|
|
|
'ability' => config('rinvex.fort.models.ability'), |
82
|
|
|
'user' => config('auth.providers.'.config('auth.guards.'.config('auth.defaults.guard').'.provider').'.model'), |
|
|
|
|
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
// Load resources |
86
|
|
|
require __DIR__.'/../../routes/breadcrumbs.php'; |
87
|
|
|
$this->loadRoutesFrom(__DIR__.'/../../routes/web.php'); |
88
|
|
|
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/fort'); |
89
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/fort'); |
90
|
|
|
$this->app->afterResolving('blade.compiler', function () { |
91
|
|
|
require __DIR__.'/../../routes/menus.php'; |
92
|
|
|
}); |
93
|
|
|
|
94
|
|
|
// Publish Resources |
95
|
|
|
! $this->app->runningInConsole() || $this->publishResources(); |
96
|
|
|
|
97
|
|
|
// Register attributes entities |
98
|
|
|
app('rinvex.attributes.entities')->push('user'); |
99
|
|
|
|
100
|
|
|
// Register menus |
101
|
|
|
$this->registerMenus(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Publish resources. |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
protected function publishResources(): void |
110
|
|
|
{ |
111
|
|
|
$this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('cortex.fort.php')], 'cortex-fort-config'); |
|
|
|
|
112
|
|
|
$this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/fort')], 'cortex-fort-lang'); |
|
|
|
|
113
|
|
|
$this->publishes([realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/fort')], 'cortex-fort-views'); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Register console commands. |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
protected function registerCommands(): void |
122
|
|
|
{ |
123
|
|
|
// Register artisan commands |
124
|
|
|
foreach ($this->commands as $key => $value) { |
125
|
|
|
$this->app->singleton($value, function ($app) use ($key) { |
|
|
|
|
126
|
|
|
return new $key(); |
127
|
|
|
}); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$this->commands(array_values($this->commands)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Register console commands. |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
protected function attachRequestMacro(): void |
139
|
|
|
{ |
140
|
|
|
Request::macro('attemptUser', function (string $guard = null) { |
141
|
|
|
$twofactor = $this->session()->get('rinvex.fort.twofactor'); |
|
|
|
|
142
|
|
|
return auth()->guard($guard)->getProvider()->retrieveById($twofactor['user_id']); |
|
|
|
|
143
|
|
|
}); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Register menus. |
148
|
|
|
* |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
protected function registerMenus(): void |
152
|
|
|
{ |
153
|
|
|
$this->app['rinvex.menus.presenters']->put('account.sidebar', \Cortex\Fort\Presenters\AccountSidebarMenuPresenter::class); |
|
|
|
|
154
|
|
|
|
155
|
|
|
Menu::make('frontarea.account.sidebar', function (MenuFactory $menu) { |
|
|
|
|
156
|
|
|
}); |
157
|
|
|
Menu::make('tenantarea.account.sidebar', function (MenuFactory $menu) { |
|
|
|
|
158
|
|
|
}); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.