-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathLauthzServiceProvider.php
70 lines (58 loc) · 2.08 KB
/
LauthzServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Lauthz;
use Illuminate\Support\ServiceProvider;
use Lauthz\EnforcerLocalizer;
use Lauthz\Loaders\ModelLoaderManager;
use Lauthz\Models\Rule;
use Lauthz\Observers\RuleObserver;
class LauthzServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([__DIR__ . '/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations');
$this->publishes([
__DIR__ . '/../config/lauthz-rbac-model.conf' => $this->app->basePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . ('lauthz-rbac-model.conf'),
__DIR__ . '/../config/lauthz.php' => $this->app->basePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . ('lauthz.php'),
], 'laravel-lauthz-config');
$this->commands([
Commands\GroupAdd::class,
Commands\PolicyAdd::class,
Commands\RoleAssign::class,
]);
}
$this->mergeConfigFrom(__DIR__ . '/../config/lauthz.php', 'lauthz');
$this->bootObserver();
$this->registerLocalizer();
}
/**
* Boot Observer.
*
* @return void
*/
protected function bootObserver()
{
Rule::observe(new RuleObserver());
}
/**
* Register bindings in the container.
*/
public function register()
{
$this->app->singleton('enforcer', fn ($app) => new EnforcerManager($app));
$this->app->singleton(ModelLoaderManager::class, fn ($app) => new ModelLoaderManager($app));
$this->app->singleton(EnforcerLocalizer::class, fn ($app) => new EnforcerLocalizer($app));
}
/**
* Register a gate that allows users to use Laravel's built-in Gate to call Enforcer.
*
* @return void
*/
protected function registerLocalizer()
{
$this->app->make(EnforcerLocalizer::class)->register();
}
}