1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author enea dhack <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Enea\Authorization; |
13
|
|
|
|
14
|
|
|
use Enea\Authorization\Blade\Compiler; |
15
|
|
|
use Enea\Authorization\Commands\InstallCommand; |
16
|
|
|
use Enea\Authorization\Contracts\PermissionContract; |
17
|
|
|
use Enea\Authorization\Contracts\RoleContract; |
18
|
|
|
use Enea\Authorization\Resolvers\DriverResolver; |
19
|
|
|
use Enea\Authorization\Support\Config; |
20
|
|
|
use Enea\Authorization\Support\Determiner; |
21
|
|
|
use Enea\Authorization\Support\Helper; |
22
|
|
|
use Illuminate\Support\ServiceProvider; |
23
|
|
|
|
24
|
|
|
class AuthorizationServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Bootstrap the application services. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
101 |
|
public function boot(): void |
32
|
|
|
{ |
33
|
101 |
|
$this->publish(); |
34
|
101 |
|
$this->registerBladeDirectives(); |
35
|
101 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Register the application services. |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
101 |
|
public function register(): void |
43
|
|
|
{ |
44
|
101 |
|
$this->app->register(EventServiceProvider::class); |
45
|
|
|
|
46
|
101 |
|
$this->commands([ |
47
|
101 |
|
InstallCommand::class |
48
|
|
|
]); |
49
|
|
|
|
50
|
101 |
|
$this->registerBindings(); |
51
|
101 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function provides() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
Authorizer::class, |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
101 |
|
private function publish(): void |
64
|
|
|
{ |
65
|
101 |
|
$this->publishes([ |
66
|
101 |
|
__DIR__ . '/../config/authorization.php' => base_path('config/authorization.php') |
67
|
|
|
]); |
68
|
101 |
|
} |
69
|
|
|
|
70
|
101 |
|
private function registerBindings(): void |
71
|
|
|
{ |
72
|
101 |
|
$this->configDriver(); |
73
|
101 |
|
$this->app->bind(PermissionContract::class, Config::permissionModel()); |
74
|
101 |
|
$this->app->bind(RoleContract::class, Config::roleModel()); |
75
|
101 |
|
$this->app->singleton('authorization.helpers', Helper::class); |
76
|
101 |
|
$this->configMiddleware(); |
77
|
101 |
|
} |
78
|
|
|
|
79
|
101 |
|
private function configDriver(): void |
80
|
|
|
{ |
81
|
101 |
|
(new DriverResolver($this->app))->make(); |
82
|
101 |
|
} |
83
|
|
|
|
84
|
101 |
|
private function configMiddleware(): void |
85
|
|
|
{ |
86
|
101 |
|
if (Determiner::isEnabledMiddleware()) { |
87
|
101 |
|
new Middleware($this->app->make('router')); |
88
|
|
|
} |
89
|
101 |
|
} |
90
|
|
|
|
91
|
101 |
|
private function registerBladeDirectives(): void |
92
|
|
|
{ |
93
|
101 |
|
(new Compiler())->make(); |
94
|
101 |
|
} |
95
|
|
|
} |
96
|
|
|
|