1 | <?php |
||
21 | class ElasticaExtension extends Extension |
||
22 | { |
||
23 | const CLIENT_ID_TEMPLATE = 'elastica.%s_client'; |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 10 | public function load(array $configs, ContainerBuilder $container) |
|
29 | { |
||
30 | 10 | $configuration = new Configuration(); |
|
31 | 10 | $config = $this->processConfiguration($configuration, $configs); |
|
32 | |||
33 | 10 | $loader = new Loader\YamlFileLoader( |
|
34 | 10 | $container, |
|
35 | 10 | new FileLocator(__DIR__ . '/../Resources/config') |
|
36 | ); |
||
37 | |||
38 | 10 | $loader->load('services.yml'); |
|
39 | |||
40 | 10 | $this->loadLogger($config, $container); |
|
41 | 10 | $this->loadClients($config, $container); |
|
42 | 10 | $this->setupAutowire($config, $container); |
|
43 | 9 | } |
|
44 | |||
45 | 10 | private function loadLogger(array $config, ContainerBuilder $container) |
|
46 | { |
||
47 | $definition = $container |
||
48 | 10 | ->register('elastica.logger', ElasticaLogger::class) |
|
49 | 10 | ->addArgument($this->createLoggerReference($config)) |
|
50 | 10 | ->addArgument('%kernel.debug%') |
|
51 | 10 | ->setPublic(true); |
|
52 | |||
53 | 10 | if ('logger' === $config['logger']) { |
|
54 | 8 | $definition->addTag('monolog.logger', ['channel' => 'elastica']); |
|
55 | } |
||
56 | 10 | } |
|
57 | |||
58 | 10 | private function createLoggerReference(array $config) |
|
69 | |||
70 | /** |
||
71 | * @param array $config |
||
72 | * @param ContainerBuilder $container |
||
73 | * @throws \Symfony\Component\DependencyInjection\Exception\LogicException |
||
74 | * @throws InvalidArgumentException |
||
75 | */ |
||
76 | 10 | private function loadClients(array $config, ContainerBuilder $container) |
|
82 | |||
83 | /** |
||
84 | * @param string $clientName |
||
85 | * @param array $clientConfig |
||
86 | * @param ContainerBuilder $container |
||
87 | * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException |
||
88 | */ |
||
89 | 6 | private function loadClient($clientName, array $clientConfig, ContainerBuilder $container) |
|
103 | |||
104 | /** |
||
105 | * Configure service auto-wiring for default Elastica client |
||
106 | * for Symfony 3.3+ |
||
107 | * |
||
108 | * @param array $config |
||
109 | * @param ContainerBuilder $container |
||
110 | * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException |
||
111 | * @throws \Symfony\Component\DependencyInjection\Exception\LogicException |
||
112 | */ |
||
113 | 10 | private function setupAutowire(array $config, ContainerBuilder $container) |
|
133 | |||
134 | 6 | private function createClientId($clientName) |
|
141 | } |
||
142 |