Failed Conditions
Push — master ( b5a0b4...819484 )
by Florent
08:00
created

PKCEMethodCompilerPass::process()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 8
nop 1
dl 0
loc 26
rs 9.2222
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-2018 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\Component\Grant\AuthorizationCode;
15
16
use OAuth2Framework\Component\AuthorizationCodeGrant\PKCEMethod\PKCEMethodManager;
17
use OAuth2Framework\ServerBundle\Service\MetadataBuilder;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
class PKCEMethodCompilerPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(PKCEMethodManager::class)) {
27
            return;
28
        }
29
30
        $definition = $container->getDefinition(PKCEMethodManager::class);
31
32
        $taggedServices = $container->findTaggedServiceIds('oauth2_server_pkce_method');
33
        $loaded = [];
34
        foreach ($taggedServices as $id => $tags) {
35
            foreach ($tags as $attributes) {
36
                if (!\array_key_exists('alias', $attributes)) {
37
                    throw new \InvalidArgumentException(\Safe\sprintf('The PKCE method  "%s" does not have any "alias" attribute.', $id));
38
                }
39
                $loaded[] = $attributes['alias'];
40
                $definition->addMethodCall('add', [new Reference($id)]);
41
            }
42
        }
43
44
        if (!$container->hasDefinition(MetadataBuilder::class)) {
45
            return;
46
        }
47
48
        $definition = $container->getDefinition(MetadataBuilder::class);
49
        $definition->addMethodCall('setCodeChallengeMethodsSupported', [new Reference(PKCEMethodManager::class)]);
50
    }
51
}
52