1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace lepiaf\SapientBundle\DependencyInjection; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
9
|
|
|
use Symfony\Component\Config\FileLocator; |
10
|
|
|
|
11
|
|
|
class SapientExtension extends Extension |
12
|
|
|
{ |
13
|
|
|
public function load(array $configs, ContainerBuilder $container) |
14
|
|
|
{ |
15
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config')); |
16
|
|
|
$loader->load('console.yml'); |
17
|
|
|
$loader->load('service.yml'); |
18
|
|
|
|
19
|
|
|
$configuration = $this->getConfiguration($configs, $container); |
20
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
21
|
|
|
|
22
|
|
|
$container->setParameter('sapient.sealing_public_keys', $config['sealing_public_keys']); |
23
|
|
|
$container->setParameter('sapient.verifying_public_keys', $config['verifying_public_keys']); |
24
|
|
|
|
25
|
|
|
if ($config['seal']['enabled']) { |
26
|
|
|
$loader->load('seal.yml'); |
27
|
|
|
|
28
|
|
|
$container->setParameter('sapient.seal.public', $config['seal']['public']); |
29
|
|
|
$container->setParameter('sapient.seal.private', $config['seal']['private']); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if ($config['sign']['enabled']) { |
33
|
|
|
$loader->load('sign.yml'); |
34
|
|
|
|
35
|
|
|
$container->setParameter('sapient.sign.public', $config['sign']['public']); |
36
|
|
|
$container->setParameter('sapient.sign.private', $config['sign']['private']); |
37
|
|
|
$container->setParameter('sapient.sign.host', $config['sign']['host']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($config['unseal_request']) { |
41
|
|
|
$loader->load('unseal_request.yml'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($config['verify_request']) { |
45
|
|
|
$loader->load('verify_request.yml'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($config['guzzle_middleware']['enabled']) { |
49
|
|
|
if ($config['guzzle_middleware']['verify']) { |
50
|
|
|
$loader->load('guzzle_middleware/verify_response.yml'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($config['guzzle_middleware']['unseal']) { |
54
|
|
|
$loader->load('guzzle_middleware/unseal_response.yml'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($config['guzzle_middleware']['requester_host']) { |
58
|
|
|
$container->setParameter('sapient.guzzle_middleware.requester_host', $config['guzzle_middleware']['requester_host']); |
59
|
|
|
$loader->load('guzzle_middleware/requester_header.yml'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($config['guzzle_middleware']['sign_request']) { |
63
|
|
|
if (!$config['sign']['enabled']) { |
64
|
|
|
throw new \LogicException('You must enable "sign" option before using "sign_request" feature.'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$loader->load('guzzle_middleware/sign_request.yml'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($config['guzzle_middleware']['seal_request']) { |
71
|
|
|
if (!$config['seal']['enabled']) { |
72
|
|
|
throw new \LogicException('You must enable "seal" option before using "sign_request" feature.'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$loader->load('guzzle_middleware/seal_request.yml'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|