1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oscer\Cms; |
4
|
|
|
|
5
|
|
|
use Illuminate\Config\Repository; |
6
|
|
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; |
7
|
|
|
use Illuminate\Support\Facades\Gate; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use Oscer\Cms\Core\Commands\InstallCommand; |
10
|
|
|
use Oscer\Cms\Core\Commands\PublishCommand; |
11
|
|
|
use Oscer\Cms\Core\Commands\ResolveOptionsCommand; |
12
|
|
|
use Oscer\Cms\Core\Models\Permission; |
13
|
|
|
use Oscer\Cms\Core\Models\Role; |
14
|
|
|
use Oscer\Cms\Core\Models\User; |
15
|
|
|
|
16
|
|
|
class OscerServiceProvider extends ServiceProvider |
17
|
|
|
{ |
18
|
|
|
public function boot(Repository $config) |
19
|
|
|
{ |
20
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'cms'); |
21
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../migrations'); |
22
|
|
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'cms'); |
23
|
|
|
|
24
|
|
|
$this->configureOscer($config); |
25
|
|
|
|
26
|
|
|
$this->registerPublishes(); |
27
|
|
|
|
28
|
|
|
Gate::before(function ($user, $ability) { |
|
|
|
|
29
|
|
|
return $user->hasRole(Role::SUPER_ADMIN_ROLE) ? true : null; |
30
|
|
|
}); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function configureOscer(Repository $config): void |
34
|
|
|
{ |
35
|
|
|
$config->set('auth.providers.cms_users', [ |
36
|
|
|
'driver' => 'eloquent', |
37
|
|
|
'model' => User::class, |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$config->set('auth.guards.web', [ |
41
|
|
|
'driver' => 'session', |
42
|
|
|
'provider' => 'cms_users', |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$config->set('permission.models', [ |
46
|
|
|
'permission' => Permission::class, |
47
|
|
|
'role' => Role::class, |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$statefulHosts = $config->get('sanctum.stateful'); |
51
|
|
|
$statefulHosts[] = $config->get('cms.backend.domain'); |
52
|
|
|
|
53
|
|
|
$config->set('sanctum.stateful', $statefulHosts); |
54
|
|
|
$config->set('sanctum.middleware.verify_csrf_token', VerifyCsrfToken::class); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function registerPublishes(): void |
58
|
|
|
{ |
59
|
|
|
if ($this->app->runningInConsole()) { |
60
|
|
|
$this->publishes([ |
61
|
|
|
__DIR__.'/../resources/stubs/CmsServiceProvider.stub' => app_path('Providers/CmsServiceProvider.php'), |
62
|
|
|
], 'cms-provider'); |
63
|
|
|
|
64
|
|
|
$this->publishes([ |
65
|
|
|
__DIR__.'/../dist' => public_path('vendor/cms'), |
66
|
|
|
], 'cms-assets'); |
67
|
|
|
|
68
|
|
|
$this->publishes([ |
69
|
|
|
__DIR__.'/../config/config.php' => config_path('cms.php'), |
70
|
|
|
], 'cms-config'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Register the application services. |
76
|
|
|
*/ |
77
|
|
|
public function register() |
78
|
|
|
{ |
79
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'cms'); |
80
|
|
|
|
81
|
|
|
$this->commands([ |
82
|
|
|
PublishCommand::class, |
83
|
|
|
ResolveOptionsCommand::class, |
84
|
|
|
InstallCommand::class, |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.