1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace GeodisBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use GeodisBundle\Service\GeodisJsonApi; |
6
|
|
|
use GeodisBundle\Service\DAO\Connection; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
12
|
|
|
|
13
|
|
|
final class GeodisExtension 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 YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
21
|
|
|
$loader->load('services.yml'); |
22
|
|
|
|
23
|
|
|
// Alias BC @geodis.rest_api -> FQCN |
24
|
|
|
if ($container->has(GeodisJsonApi::class) && !$container->hasAlias('geodis.rest_api')) { |
25
|
|
|
$container->setAlias('geodis.rest_api', (new Alias(GeodisJsonApi::class))->setPublic(true)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
// Injecter la config + lazy |
29
|
|
|
foreach ([GeodisJsonApi::class, Connection::class, 'geodis.rest_api'] as $id) { |
30
|
|
|
if ($container->hasDefinition($id)) { |
31
|
|
|
$def = $container->getDefinition($id); |
32
|
|
|
$def->setLazy(true) |
33
|
|
|
->addMethodCall('setConfig', [$config]); |
34
|
|
|
break; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|