|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Rest\ClientBundle\DependencyInjection; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\{ |
|
7
|
|
|
HttpKernel\DependencyInjection\Extension, |
|
8
|
|
|
DependencyInjection\ContainerBuilder, |
|
9
|
|
|
DependencyInjection\Loader, |
|
10
|
|
|
Config\FileLocator |
|
11
|
|
|
}; |
|
12
|
|
|
|
|
13
|
|
|
final class InnmindRestClientExtension extends Extension |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
5 |
|
public function load(array $configs, ContainerBuilder $container) |
|
19
|
|
|
{ |
|
20
|
5 |
|
$loader = new Loader\YamlFileLoader( |
|
21
|
|
|
$container, |
|
22
|
5 |
|
new FileLocator(__DIR__.'/../Resources/config') |
|
23
|
|
|
); |
|
24
|
5 |
|
$loader->load('services.yml'); |
|
25
|
5 |
|
$config = $this->processConfiguration( |
|
26
|
5 |
|
new Configuration, |
|
27
|
|
|
$configs |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
$this |
|
31
|
4 |
|
->configureLogLevel($config, $container) |
|
32
|
4 |
|
->configureCacheDirectory($config, $container) |
|
33
|
4 |
|
->registerTypes($config['types'], $container) |
|
34
|
4 |
|
->registerContentTypeFormats($config['content_type'], $container); |
|
35
|
4 |
|
} |
|
36
|
|
|
|
|
37
|
4 |
|
private function configureLogLevel( |
|
38
|
|
|
array $config, |
|
39
|
|
|
ContainerBuilder $container |
|
40
|
|
|
): self { |
|
41
|
4 |
|
if (isset($config['log_level'])) { |
|
42
|
|
|
$container |
|
43
|
1 |
|
->getDefinition('innmind_rest_client.transport.logger') |
|
44
|
1 |
|
->replaceArgument(2, $config['log_level']); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
private function configureCacheDirectory( |
|
51
|
|
|
array $config, |
|
52
|
|
|
ContainerBuilder $container |
|
53
|
|
|
): self { |
|
54
|
4 |
|
if (isset($config['cache_directory'])) { |
|
55
|
|
|
$container |
|
56
|
1 |
|
->getDefinition('innmind_rest_client.filesystem') |
|
57
|
1 |
|
->replaceArgument(0, $config['cache_directory']); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
private function registerTypes(array $types, ContainerBuilder $container): self |
|
64
|
|
|
{ |
|
65
|
4 |
|
$definition = $container->getDefinition( |
|
66
|
4 |
|
'innmind_rest_client.definition.types' |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
4 |
|
foreach ($types as $type) { |
|
70
|
1 |
|
$definition->addMethodCall( |
|
71
|
1 |
|
'register', |
|
72
|
1 |
|
[$type] |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
4 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
4 |
|
private function registerContentTypeFormats( |
|
80
|
|
|
array $formats, |
|
81
|
|
|
ContainerBuilder $container |
|
82
|
|
|
): self { |
|
83
|
|
|
$container |
|
84
|
4 |
|
->getDefinition('innmind_rest_client.formats.content_type') |
|
85
|
4 |
|
->replaceArgument(0, $formats); |
|
86
|
|
|
|
|
87
|
4 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|