Failed Conditions
Push — master ( af58b3...cca06a )
by Florent
04:10
created

CustomMetadataCompilerPass::process()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 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\DependencyInjection\Compiler;
15
16
use OAuth2Framework\Bundle\Server\Service\MetadataBuilder;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
21
final class CustomMetadataCompilerPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->hasDefinition(MetadataBuilder::class)) {
29
            return;
30
        }
31
32
        $definition = $container->getDefinition(MetadataBuilder::class);
33
        $customRoutes = $container->getParameter('oauth2_server.endpoint.metadata.custom_routes');
34
        foreach ($customRoutes as $key => $parameters) {
35
            $this->addMethodCall($definition, 'setRoute', [$key, $parameters['route_name'], $parameters['route_parameters']]);
36
        }
37
38
        $customValues = $container->getParameter('oauth2_server.endpoint.metadata.custom_values');
39
        foreach ($customValues as $key => $parameters) {
40
            $this->addMethodCall($definition, 'addKeyValuePair', [$key, $parameters]);
41
        }
42
    }
43
44
    /**
45
     * @param Definition $definition
46
     * @param string     $method
47
     * @param array      $parameters
48
     */
49
    private function addMethodCall(Definition $definition, string $method, array $parameters)
50
    {
51
        $definition->addMethodCall($method, $parameters);
52
    }
53
}
54