AclServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 61
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A registerBladeDirectives() 0 32 1
A register() 0 6 1
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