Test Failed
Push — master ( 3e81ac...787e81 )
by Iman
02:36
created

HeyManServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Support\Facades\Gate;
6
use Illuminate\Support\ServiceProvider;
7
8
class HeyManServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->defineGates();
13
14
        $this->loadMigrationsFrom(__DIR__.'/migrations');
15
        (new RouteAuthorizer())->authorizeMatchedRoutes($this->app);
16
    }
17
18
    public function register()
19
    {
20
        $this->app->singleton(HeyMan::class, HeyMan::class);
21
        $this->app->singleton('hey_man_authorizer', ConditionApplier::class);
22
        $this->app->singleton('hey_man_route_authorizer', RouteConditionApplier::class);
23
        $this->app->singleton(YouShouldHave::class, YouShouldHave::class);
24
        $this->app->singleton('hey_man_responder', Responder::class);
25
26
        $this->mergeConfigFrom(
27
            __DIR__.'/../config/heyMan.php',
28
            'heyMan'
29
        );
30
    }
31
32
    private function defineGates(): void
33
    {
34
        Gate::define('heyman.youShouldHaveRole', function ($user, $role) {
35
            return $user->role == $role;
36
        });
37
    }
38
}