|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bankiru\Api\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
7
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
8
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
9
|
|
|
|
|
10
|
|
|
class Configuration implements ConfigurationInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** {@inheritdoc} */ |
|
13
|
6 |
|
public function getConfigTreeBuilder() |
|
14
|
|
|
{ |
|
15
|
6 |
|
$builder = new TreeBuilder(); |
|
16
|
6 |
|
$root = $builder->root('api_client'); |
|
17
|
|
|
|
|
18
|
6 |
|
$logger = $root->children()->arrayNode('logger'); |
|
19
|
6 |
|
$logger->addDefaultsIfNotSet(); |
|
20
|
6 |
|
$logger->children()->scalarNode('id')->defaultValue('logger'); |
|
21
|
|
|
|
|
22
|
6 |
|
$root->children()->booleanNode('profiling')->defaultValue('%kernel.debug%'); |
|
23
|
|
|
|
|
24
|
6 |
|
$metadataCache = $root->children()->arrayNode('metadata_cache'); |
|
25
|
6 |
|
$metadataCache->canBeEnabled(); |
|
26
|
6 |
|
$metadataCache->children()->scalarNode('service')->info( |
|
27
|
|
|
Cache::class . ' Implementation service id. Required if enabled' |
|
28
|
6 |
|
)->defaultNull(); |
|
29
|
6 |
|
$metadataCache->beforeNormalization()->ifString()->then( |
|
30
|
1 |
|
function ($v) { |
|
31
|
|
|
return ['service' => $v, 'enabled' => true]; |
|
32
|
1 |
|
} |
|
33
|
7 |
|
); |
|
34
|
|
|
|
|
35
|
6 |
|
$cache = $root->children()->arrayNode('entity_cache'); |
|
36
|
7 |
|
$cache->canBeEnabled(); |
|
37
|
7 |
|
$cache->children()->scalarNode('service')->info('PSR-6 Cache service. Required if enabled'); |
|
38
|
7 |
|
$cache->children()->scalarNode('logger')->defaultNull()->info('PSR-3 Log service for cache'); |
|
39
|
7 |
|
$cache->beforeNormalization()->ifString()->then( |
|
40
|
1 |
|
function ($v) { |
|
41
|
2 |
|
return ['service' => $v, 'enabled' => true]; |
|
42
|
1 |
|
} |
|
43
|
7 |
|
); |
|
44
|
7 |
|
$configuration = $cache->children()->arrayNode('configuration'); |
|
45
|
7 |
|
$configuration->useAttributeAsKey('class'); |
|
46
|
1 |
|
/** @var ArrayNodeDefinition $confProto */ |
|
47
|
7 |
|
$confProto = $configuration->prototype('array'); |
|
48
|
7 |
|
$confProto->children()->scalarNode('ttl')->isRequired(); |
|
49
|
7 |
|
$confProto->beforeNormalization() |
|
50
|
7 |
|
->ifTrue( |
|
51
|
1 |
|
function ($v) { |
|
52
|
2 |
|
return is_int($v); |
|
53
|
1 |
|
} |
|
54
|
7 |
|
) |
|
55
|
7 |
|
->then( |
|
56
|
2 |
|
function ($v) { |
|
57
|
2 |
|
return ['ttl' => $v]; |
|
58
|
1 |
|
} |
|
59
|
7 |
|
); |
|
60
|
7 |
|
$confProto->children()->variableNode('extra') |
|
61
|
7 |
|
->info('Extra data for entity cache configuration') |
|
62
|
7 |
|
->defaultValue([]); |
|
63
|
7 |
|
$confProto->ignoreExtraKeys(false); |
|
64
|
7 |
|
$confProto->canBeEnabled(); |
|
65
|
1 |
|
|
|
66
|
7 |
|
return $builder; |
|
67
|
1 |
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|