ResourceServerBootstrapper::getBindings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Bootstrappers\Oauth2;
6
7
use AbterPhp\Admin\Oauth2\Repository;
8
use AbterPhp\Framework\Constant\Env;
9
use League\OAuth2\Server\ResourceServer;
10
use Opulence\Databases\ConnectionPools\ConnectionPool;
11
use Opulence\Ioc\Bootstrappers\Bootstrapper;
12
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
13
use Opulence\Ioc\IContainer;
14
use Opulence\Ioc\IocException;
15
use Opulence\Orm\Ids\Generators\UuidV4Generator;
16
17
class ResourceServerBootstrapper extends Bootstrapper implements ILazyBootstrapper
18
{
19
    /**
20
     * @return string[]
21
     */
22
    public function getBindings(): array
23
    {
24
        return [ResourceServer::class];
25
    }
26
27
    /**
28
     * @inheritdoc
29
     * @throws IocException
30
     */
31
    public function registerBindings(IContainer $container)
32
    {
33
        /** @var UuidV4Generator $uuidGenerator */
34
        $uuidGenerator = $container->resolve(UuidV4Generator::class);
35
36
        /** @var ConnectionPool $connectionPool */
37
        $connectionPool = $container->resolve(ConnectionPool::class);
38
39
        // Init our repositories
40
        $accessTokenRepository = new Repository\AccessToken($uuidGenerator, $connectionPool);
41
42
        $publicKeyPath = getenv(Env::OAUTH2_PUBLIC_KEY_PATH);
43
44
        $server = new ResourceServer(
45
            $accessTokenRepository,
46
            $publicKeyPath
47
        );
48
49
        $container->bindInstance(ResourceServer::class, $server);
50
    }
51
}
52