JwtServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 6
dl 0
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 18 1
A register() 0 22 1
1
<?php
2
3
namespace Framgia\Jwt;
4
5
use Illuminate\Auth\AuthManager;
6
use Framgia\Jwt\Storage\CacheStorage;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\ServiceProvider;
9
use Framgia\Jwt\Signers\Factory as SignerFactory;
10
use Illuminate\Contracts\Cache\Repository as Cache;
11
use Framgia\Jwt\Contracts\Signer as SignerContract;
12
use Framgia\Jwt\Contracts\Storage as StorageContract;
13
14
class JwtServiceProvider extends ServiceProvider
15
{
16
    public function boot()
17
    {
18
        $this->publishes([
19
            __DIR__ . '/../config/jwt.php' => config_path('api.php')
20
        ]);
21
22
        $this->mergeConfigFrom(__DIR__ . '/../config/jwt.php', 'jwt');
23
24
        $manager = $this->app[AuthManager::class];
25
26
        $manager->extend('jwt', function ($app, $name, $config) use ($manager) {
27
            $guard = new Guard($manager->createUserProvider($config['provider']), $app[Request::class], $app[Blacklist::class], $app[SignerContract::class]);
28
29
            $app->refresh(Request::class, $guard, 'setRequest');
30
31
            return $guard;
32
        });
33
    }
34
35
    /**
36
     * Register services
37
     *
38
     * @return void
39
     */
40
    public function register()
41
    {
42
        $this->app->singleton(StorageManager::class, function ($app) {
43
            return new StorageManager($app);
44
        });
45
46
        $this->app->singleton(Blacklist::class, function ($app) {
47
            return new Blacklist($app[StorageContract::class]);
48
        });
49
50
        $this->app->singleton(SignerFactory::class, function ($app) {
51
            return new SignerFactory($app);
52
        });
53
54
        $this->app->bind(SignerContract::class, function ($app) {
55
            return $app[SignerFactory::class]->driver();
56
        });
57
58
        $this->app->bind(StorageContract::class, function ($app) {
59
            return $app[StorageManager::class]->driver();
60
        });
61
    }
62
}
63