Failed Conditions
Push — master ( f0e999...0c3180 )
by Florent
03:06
created

OAuth2FrameworkServerBundle::loadDoctrineSchemas()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle;
15
16
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
17
use OAuth2Framework\ServerBundle\DependencyInjection\OAuth2FrameworkExtension;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
20
use Symfony\Component\HttpKernel\Bundle\Bundle;
21
22
class OAuth2FrameworkServerBundle extends Bundle
23
{
24
    /**
25
     * @var Component\Component[]
26
     */
27
    private $components = [];
28
29
    public function __construct()
30
    {
31
        foreach ($this->getComponents() as $component) {
32
            $this->components[$component->name()] = $component;
33
        }
34
    }
35
36
    public function getContainerExtension(): ExtensionInterface
37
    {
38
        return new OAuth2FrameworkExtension('oauth2_server', $this->components);
39
    }
40
41
    public function build(ContainerBuilder $container): void
42
    {
43
        parent::build($container);
44
        foreach ($this->components as $component) {
45
            $component->build($container);
46
        }
47
        $this->loadDoctrineSchemas($container);
48
    }
49
50
    private function loadDoctrineSchemas(ContainerBuilder $container): void
51
    {
52
        if (!class_exists(DoctrineOrmMappingsPass::class)) {
53
            return;
54
        }
55
        $container->addCompilerPass(DoctrineOrmMappingsPass::createYamlMappingDriver([
56
            realpath(__DIR__.'/Resources/config/doctrine-mapping/AccessToken') => 'OAuth2Framework\Component\Core\AccessToken',
57
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Client') => 'OAuth2Framework\Component\Core\Client',
58
        ]));
59
    }
60
61
    /**
62
     * @return Component\Component[]
63
     */
64
    private function getComponents(): array
65
    {
66
        return [
67
            new Component\Core\TrustedIssuerSource(),
68
            new Component\Core\ClientSource(),
69
            new Component\Core\AccessTokenSource(),
70
            new Component\Core\UserAccountSource(),
71
            new Component\Core\ServicesSource(),
72
            new Component\Core\ResourceServerSource(),
73
            new Component\ClientRule\ClientRuleSource(),
74
            new Component\ClientAuthentication\ClientAuthenticationSource(),
75
76
            new Component\Scope\ScopeSource(),
77
            new Component\TokenType\TokenTypeSource(),
78
            new Component\Endpoint\EndpointSource(),
79
            new Component\Grant\GrantSource(),
80
            new Component\OpenIdConnect\OpenIdConnectSource(),
81
82
            /*
83
            new Component\HttpSource(),
84
            new Component\KeySet(),*/
85
        ];
86
    }
87
}
88