|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace FH\Bundle\UserAgentBundle\DependencyInjection; |
|
5
|
|
|
|
|
6
|
|
|
use FH\Bundle\UserAgentBundle\Repository\UserAgentRepositoryInterface; |
|
7
|
|
|
use Symfony\Component\Config\FileLocator; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
12
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Evert Harmeling <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
final class FHUserAgentExtension extends Extension |
|
18
|
|
|
{ |
|
19
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
20
|
|
|
{ |
|
21
|
|
|
$configuration = new Configuration(); |
|
22
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
23
|
|
|
|
|
24
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
25
|
|
|
$loader->load('repository.yaml'); |
|
26
|
|
|
|
|
27
|
|
|
$this->configureRepository($container, $config['repository']); |
|
28
|
|
|
$this->configureResponseListener($container, $config['response_listener']); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private function configureRepository(ContainerBuilder $containerBuilder, string $repository): void |
|
32
|
|
|
{ |
|
33
|
|
|
$containerBuilder->addAliases([ |
|
34
|
|
|
UserAgentRepositoryInterface::class => $repository |
|
35
|
|
|
]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function configureResponseListener(ContainerBuilder $containerBuilder, array $config): void |
|
39
|
|
|
{ |
|
40
|
|
|
if (isset($config['criteria'])) { |
|
41
|
|
|
$criteria = $config['criteria']; |
|
42
|
|
|
} else { |
|
43
|
|
|
$criteria = []; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$containerBuilder->addDefinitions([ |
|
47
|
|
|
$config['class'] => |
|
48
|
|
|
(new Definition()) |
|
49
|
|
|
->setAutoconfigured(true) |
|
50
|
|
|
->setAutowired(true) |
|
51
|
|
|
->setPublic(false) |
|
52
|
|
|
->addTag('kernel.event_listener', |
|
53
|
|
|
[ |
|
54
|
|
|
'event' => KernelEvents::RESPONSE |
|
55
|
|
|
] |
|
56
|
|
|
) |
|
57
|
|
|
->setBindings([ |
|
58
|
|
|
'$criteria' => $criteria |
|
59
|
|
|
]) |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|