|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DH\AuditorBundle\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use DH\Auditor\Provider\ProviderInterface; |
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
12
|
|
|
|
|
13
|
|
|
class DHAuditorExtension extends Extension |
|
14
|
|
|
{ |
|
15
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
16
|
|
|
{ |
|
17
|
|
|
$configuration = new Configuration(); |
|
18
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
19
|
|
|
|
|
20
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
21
|
|
|
$loader->load('services.yaml'); |
|
22
|
|
|
|
|
23
|
|
|
$auditorConfig = $config; |
|
24
|
|
|
unset($auditorConfig['providers']); |
|
25
|
|
|
$container->setParameter('dh_auditor.configuration', $auditorConfig); |
|
26
|
|
|
|
|
27
|
|
|
$this->loadProviders($container, $config); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
private function loadProviders(ContainerBuilder $container, array $config): void |
|
31
|
|
|
{ |
|
32
|
|
|
foreach ($config['providers'] as $providerName => $providerConfig) { |
|
33
|
|
|
$container->setParameter('dh_auditor.provider.'.$providerName.'.configuration', $providerConfig); |
|
34
|
|
|
|
|
35
|
|
|
if (method_exists($container, 'registerAliasForArgument')) { |
|
36
|
|
|
$serviceId = 'dh_auditor.provider.'.$providerName; |
|
37
|
|
|
$container->registerAliasForArgument($serviceId, ProviderInterface::class, sprintf('%sProvider', $providerName)); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|