1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Napp\Core\Acl; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Illuminate\View\Compilers\BladeCompiler; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class AclServiceProvider. |
10
|
|
|
*/ |
11
|
|
|
class AclServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
94 |
|
public function register() |
17
|
|
|
{ |
18
|
94 |
|
$this->app->bind(AclServiceInterface::class, AclService::class); |
19
|
|
|
|
20
|
94 |
|
$this->registerBladeDirectives(); |
21
|
94 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Perform post-registration booting of services. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
94 |
|
public function boot() |
29
|
|
|
{ |
30
|
94 |
|
$this->publishes([__DIR__.'/../database/migrations' => base_path('database/migrations')], 'migrations'); |
31
|
94 |
|
$this->publishes([__DIR__.'/../config/acl.php' => config_path('acl.php')], 'config'); |
32
|
94 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Register Blade directives. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
94 |
|
protected function registerBladeDirectives() |
40
|
|
|
{ |
41
|
|
|
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { |
42
|
|
|
$bladeCompiler->directive('hasrole', function ($role) { |
43
|
2 |
|
return "<?php if(has_role({$role})): ?>"; |
44
|
8 |
|
}); |
45
|
|
|
$bladeCompiler->directive('endhasrole', function () { |
46
|
2 |
|
return '<?php endif; ?>'; |
47
|
8 |
|
}); |
48
|
|
|
|
49
|
|
|
$bladeCompiler->directive('may', function ($permission) { |
50
|
2 |
|
return "<?php if(may({$permission})): ?>"; |
51
|
8 |
|
}); |
52
|
|
|
$bladeCompiler->directive('endmay', function () { |
53
|
2 |
|
return '<?php endif; ?>'; |
54
|
8 |
|
}); |
55
|
|
|
|
56
|
|
|
$bladeCompiler->directive('maynot', function ($permission) { |
57
|
2 |
|
return "<?php if(maynot({$permission})): ?>"; |
58
|
8 |
|
}); |
59
|
|
|
$bladeCompiler->directive('endmaynot', function () { |
60
|
2 |
|
return '<?php endif; ?>'; |
61
|
8 |
|
}); |
62
|
|
|
|
63
|
|
|
$bladeCompiler->directive('mayall', function ($permissions) { |
64
|
2 |
|
return "<?php if(mayall({$permissions})): ?>"; |
65
|
8 |
|
}); |
66
|
|
|
$bladeCompiler->directive('endmayall', function () { |
67
|
2 |
|
return '<?php endif; ?>'; |
68
|
8 |
|
}); |
69
|
94 |
|
}); |
70
|
94 |
|
} |
71
|
|
|
} |
72
|
|
|
|