1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bicycle\TesseractBridgeBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Bicycle\Tesseract\Bridge; |
6
|
|
|
use Bicycle\TesseractBridgeBundle\DataCollector\TesseractBridgeDataCollector; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\DependencyInjection; |
9
|
|
|
|
10
|
|
|
class BicycleTesseractBridgeExtension extends DependencyInjection\Extension\Extension |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritDoc} |
14
|
|
|
*/ |
15
|
|
|
public function load(array $configs, DependencyInjection\ContainerBuilder $container): void |
16
|
|
|
{ |
17
|
|
|
$configuration = new Configuration(); |
18
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
19
|
|
|
|
20
|
|
|
$loader = new DependencyInjection\Loader\YamlFileLoader( |
21
|
|
|
$container, |
22
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
23
|
|
|
); |
24
|
|
|
$loader->load('tesseract_bridge.yaml'); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set configuration to collector. |
28
|
|
|
*/ |
29
|
|
|
$definition = $container->getDefinition(TesseractBridgeDataCollector::class); |
30
|
|
|
$definition->replaceArgument(2, $config); |
31
|
|
|
|
32
|
|
|
$arguments = []; |
33
|
|
|
/** @psalm-suppress MixedArrayAccess */ |
34
|
|
|
if ($config['integrations']['cli']['enabled']) { |
35
|
|
|
/** @psalm-suppress MixedArrayAccess */ |
36
|
|
|
$arguments['binary_path'] = (string) $config['integrations']['cli']['path']; |
37
|
|
|
$definition->replaceArgument( |
38
|
|
|
0, |
39
|
|
|
$container->getDefinition('bicycle.tesseract_bridge.integrations.cli') |
40
|
|
|
); |
41
|
|
|
} else { |
42
|
|
|
// Remove not configured integration |
43
|
|
|
$container->removeDefinition('bicycle.tesseract_bridge.integrations.cli'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @psalm-suppress MixedArrayAccess */ |
47
|
|
|
if ($config['integrations']['ffi']['enabled']) { |
48
|
|
|
/** @psalm-suppress MixedArrayAccess */ |
49
|
|
|
$arguments['library_path'] = (string) $config['integrations']['ffi']['path']; |
50
|
|
|
$definition->replaceArgument( |
51
|
|
|
1, |
52
|
|
|
$container->getDefinition('bicycle.tesseract_bridge.integrations.ffi') |
53
|
|
|
); |
54
|
|
|
} else { |
55
|
|
|
// Remove not configured integration |
56
|
|
|
$container->removeDefinition('bicycle.tesseract_bridge.integrations.ffi'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Set parameters for configuration. |
61
|
|
|
*/ |
62
|
|
|
$definition = $container->getDefinition(Bridge\Configuration::class); |
63
|
|
|
$definition->replaceArgument(0, $arguments); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|