1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Acl; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; |
6
|
|
|
use Illuminate\View\Compilers\BladeCompiler; |
7
|
|
|
|
8
|
|
|
class AclServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Register any application authentication / authorization services. |
12
|
|
|
* |
13
|
|
|
* @param GateRegistrar $gate |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function boot(GateRegistrar $gate) |
17
|
|
|
{ |
18
|
|
|
$gate->register(); |
19
|
|
|
|
20
|
|
|
$this->publishConfig(); |
21
|
|
|
$this->publishMigrations(); |
22
|
|
|
$this->registerPolicies(); |
23
|
|
|
$this->registerBladeDirectives(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Publish package config file. |
28
|
|
|
*/ |
29
|
|
|
protected function publishConfig() |
30
|
|
|
{ |
31
|
|
|
$path = __DIR__.'/../config/acl.php'; |
32
|
|
|
|
33
|
|
|
$this->publishes([$path => config_path('acl.php')], 'laravel-acl'); |
34
|
|
|
|
35
|
|
|
$this->mergeConfigFrom($path, 'acl'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Publish package migration files. |
40
|
|
|
*/ |
41
|
|
|
protected function publishMigrations() |
42
|
|
|
{ |
43
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../migrations'); |
44
|
|
|
$this->publishes([ |
45
|
|
|
__DIR__.'/../migrations' => database_path('migrations'), |
46
|
|
|
], 'laravel-acl'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register custom blade directives. |
51
|
|
|
*/ |
52
|
|
|
protected function registerBladeDirectives() |
53
|
|
|
{ |
54
|
|
|
/** @var BladeCompiler $blade */ |
55
|
|
|
$blade = $this->app['blade.compiler']; |
56
|
|
|
$blade->directive('canAtLeast', function ($expression) { |
57
|
|
|
return "<?php if (app('laravel-acl.directives.canAtLeast')->handle({$expression})): ?>"; |
58
|
|
|
}); |
59
|
|
|
$blade->directive('endCanAtLeast', function ($expression) { |
|
|
|
|
60
|
|
|
return '<?php endif; ?>'; |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
$blade->directive('role', function ($expression) { |
64
|
|
|
return "<?php if (app('laravel-acl.directives.role')->handle({$expression})): ?>"; |
65
|
|
|
}); |
66
|
|
|
$blade->directive('endRole', function ($expression) { |
|
|
|
|
67
|
|
|
return '<?php endif; ?>'; |
68
|
|
|
}); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Register providers. |
73
|
|
|
*/ |
74
|
|
|
public function register() |
75
|
|
|
{ |
76
|
|
|
$this->app->singleton('laravel-acl.directives.canAtLeast', Directives\CanAtLeastDirective::class); |
77
|
|
|
$this->app->singleton('laravel-acl.directives.role', Directives\RoleDirective::class); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.