Completed
Push — feature/ra-locations ( 8e7bb5 )
by Boy
12:38
created

SurfnetStepupMiddlewareClientExtension::load()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 36
rs 8.8571
cc 1
eloc 23
nc 1
nop 2
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddlewareClientBundle\DependencyInjection;
20
21
use Symfony\Component\Config\Definition\Processor;
22
use Symfony\Component\Config\FileLocator;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
25
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
26
27
class SurfnetStepupMiddlewareClientExtension extends Extension
28
{
29
    public function load(array $config, ContainerBuilder $container)
30
    {
31
        $processor = new Processor();
32
        $config = $processor->processConfiguration(new Configuration(), $config);
33
34
        $loader = new YamlFileLoader(
35
            $container,
36
            new FileLocator(__DIR__.'/../Resources/config')
37
        );
38
        $loader->load('services.yml');
39
40
        $commandService = $container->getDefinition('surfnet_stepup_middleware_client.library.service.command');
41
        $commandService->replaceArgument(1, $config['authorisation']['username']);
42
        $commandService->replaceArgument(2, $config['authorisation']['password']);
43
44
        $guzzle = $container->getDefinition('surfnet_stepup_middleware_client.guzzle.commands');
45
        $guzzle->replaceArgument(0, ['base_url' => $config['url']['command_api']]);
46
47
        $guzzle = $container->getDefinition('surfnet_stepup_middleware_client.guzzle.api');
48
        $guzzle->replaceArgument(
49
            0,
50
            [
51
                'base_url' => $config['url']['api'],
52
                'defaults' => [
53
                    'auth' => [
54
                        $config['authorisation']['username'],
55
                        $config['authorisation']['password'],
56
                        'basic'
57
                    ],
58
                    'headers' => [
59
                        'Accept' => 'application/json'
60
                    ]
61
                ]
62
            ]
63
        );
64
    }
65
}
66