Failed Conditions
Push — master ( e0834e...22ddb5 )
by Florent
03:18
created

OAuth2FrameworkServerBundle   C

Complexity

Total Complexity 9

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 47

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 47
dl 0
loc 113
rs 5
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A getContainerExtension() 0 4 1
A getRequiredBundles() 0 4 1
A build() 0 7 2
A checkRequiredBundles() 0 13 3
A getCompilerPasses() 0 48 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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\Bundle\Server;
15
16
use OAuth2Framework\Bundle\Server\DependencyInjection\Compiler;
17
use OAuth2Framework\Bundle\Server\DependencyInjection\OAuth2FrameworkServerExtension;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\HttpKernel\Bundle\Bundle;
21
22
final class OAuth2FrameworkServerBundle extends Bundle
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function boot()
28
    {
29
        parent::boot();
30
        $this->container->get('twig.loader')->addPath(__DIR__.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'views', 'OAuth2FrameworkServerBundle');
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getContainerExtension($alias = 'oauth2_server')
37
    {
38
        return new OAuth2FrameworkServerExtension($alias);
39
    }
40
41
    /**
42
     * Lists the required bundles.
43
     *
44
     * @return string[]
45
     */
46
    protected function getRequiredBundles()
47
    {
48
        return ['JoseFrameworkBundle', 'SignatureBundle', 'EncryptionBundle', 'SensioFrameworkExtraBundle', 'SimpleBusCommandBusBundle', 'SimpleBusEventBusBundle'];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function build(ContainerBuilder $container)
55
    {
56
        $this->checkRequiredBundles($container);
57
        foreach ($this->getCompilerPasses() as $pass) {
58
            $container->addCompilerPass($pass);
59
        }
60
    }
61
62
    /**
63
     * Checks if the required bundles are enabled.
64
     *
65
     * @param ContainerBuilder $container
66
     *
67
     * @throws \LogicException
68
     */
69
    private function checkRequiredBundles(ContainerBuilder $container)
70
    {
71
        $requiredBundles = $this->getRequiredBundles();
72
        if (empty($requiredBundles)) {
73
            return;
74
        }
75
        $enabledBundles = $container->getParameter('kernel.bundles');
76
        $disabledBundles = array_diff($requiredBundles, array_keys($enabledBundles));
77
78
        if (!empty($disabledBundles)) {
79
            throw new \LogicException(sprintf('%s requires the following bundle(s): %s', $this->getName(), implode(', ', $disabledBundles)));
80
        }
81
    }
82
83
    /**
84
     * @return CompilerPassInterface[]
85
     */
86
    private function getCompilerPasses(): array
87
    {
88
        return [
89
            new Compiler\ClientRuleCompilerPass(),
90
            new Compiler\ScopePolicyCompilerPass(),
91
            new Compiler\ResponseFactoryCompilerPass(),
92
            new Compiler\TokenEndpointAuthMethodCompilerPass(),
93
            new Compiler\TokenIntrospectionEndpointAuthMethodCompilerPass(),
94
            new Compiler\GrantTypeCompilerPass(),
95
            new Compiler\TokenRouteCompilerPass(),
96
            new Compiler\TokenTypeCompilerPass(),
97
            new Compiler\PKCEMethodCompilerPass(),
98
            new Compiler\TokenIntrospectionRouteCompilerPass(),
99
            new Compiler\TokenRevocationRouteCompilerPass(),
100
            new Compiler\TokenTypeHintCompilerPass(),
101
            new Compiler\IssuerDiscoveryCompilerPass(),
102
            new Compiler\ResponseModeCompilerPass(),
103
            new Compiler\AccessTokenHandlerCompilerPass(),
104
            new Compiler\TokenEndpointExtensionCompilerPass(),
105
            new Compiler\AuthorizationEndpointRouteCompilerPass(),
106
            new Compiler\UserInfoScopeSupportCompilerPass(),
107
            new Compiler\UserinfoRouteCompilerPass(),
108
            new Compiler\UserinfoEndpointSignatureCompilerPass(),
109
            new Compiler\UserinfoEndpointEncryptionCompilerPass(),
110
            new Compiler\UserInfoPairwiseSubjectCompilerPass(),
111
            new Compiler\ClaimSourceCompilerPass(),
112
            new Compiler\UserAccountDiscoveryCompilerPass(),
113
            new Compiler\ParameterCheckerCompilerPass(),
114
            new Compiler\ResponseTypeCompilerPass(),
115
            new Compiler\BeforeConsentScreenCompilerPass(),
116
            new Compiler\AfterConsentScreenCompilerPass(),
117
            new Compiler\InitialAccessTokenCompilerPass(),
118
            new Compiler\ClientAssertionJWTEncryptionSupportConfigurationCompilerPass(),
119
            new Compiler\SessionManagementRouteCompilerPass(),
120
            new Compiler\ClientConfigurationEndpointRouteCompilerPass(),
121
            new Compiler\ClientRegistrationEndpointRouteCompilerPass(),
122
            new Compiler\MetadataRouteCompilerPass(),
123
            new Compiler\SignedMetadataCompilerPass(),
124
            new Compiler\IdTokenMetadataCompilerPass(),
125
            new Compiler\ClientJwtAssertionMetadataCompilerPass(),
126
            new Compiler\JwksUriEndpointRouteCompilerPass(),
127
            new Compiler\CommonMetadataCompilerPass(),
128
            new Compiler\CustomMetadataCompilerPass(),
129
            new Compiler\ScopeMetadataCompilerPass(),
130
            new Compiler\AuthorizationRequestMetadataCompilerPass(),
131
            new Compiler\RequestObjectCompilerPass(),
132
        ];
133
    }
134
}
135