|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Surfnet\YubikeyApiClientBundle\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
9
|
|
|
use Symfony\Component\Config\FileLocator; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
12
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
13
|
|
|
|
|
14
|
|
|
class SurfnetYubikeyApiClientExtension extends Extension |
|
15
|
|
|
{ |
|
16
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
17
|
|
|
{ |
|
18
|
|
|
$processor = new Processor(); |
|
19
|
|
|
$configs = $processor->processConfiguration(new Configuration(), $configs); |
|
20
|
|
|
|
|
21
|
|
|
$credentials = $configs['credentials']; |
|
22
|
|
|
|
|
23
|
|
|
if (!is_array($credentials)) { |
|
24
|
|
|
throw new InvalidArgumentException('Invalid YubikeyApiClient credentials.'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$clientId = $credentials['client_id']; |
|
28
|
|
|
assert(is_string($clientId) || is_int($clientId)); |
|
29
|
|
|
|
|
30
|
|
|
$secret = $credentials['client_secret']; |
|
31
|
|
|
assert(is_string($secret)); |
|
32
|
|
|
|
|
33
|
|
|
$container->setParameter('surfnet_yubikey_api_client.credentials.client_id', (string)$clientId); |
|
34
|
|
|
$container->setParameter('surfnet_yubikey_api_client.credentials.client_secret', $secret); |
|
35
|
|
|
|
|
36
|
|
|
$loader = new YamlFileLoader( |
|
37
|
|
|
$container, |
|
38
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
|
39
|
|
|
); |
|
40
|
|
|
$loader->load('services.yml'); |
|
41
|
|
|
|
|
42
|
|
|
//check for test environment |
|
43
|
|
|
if ($container->getParameter('kernel.environment') === 'test') { |
|
44
|
|
|
$loader->load('services_test.yml'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|