|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: scaytrase |
|
4
|
|
|
* Created: 2016-02-13 10:12 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Bankiru\Api\Rpc\DependencyInjection; |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
10
|
|
|
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition; |
|
11
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
12
|
|
|
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition; |
|
13
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
14
|
|
|
|
|
15
|
|
|
final class Configuration implements ConfigurationInterface |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Generates the configuration tree builder. |
|
20
|
|
|
* |
|
21
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder |
|
22
|
|
|
*/ |
|
23
|
1 |
|
public function getConfigTreeBuilder() |
|
24
|
|
|
{ |
|
25
|
1 |
|
$builder = new TreeBuilder(); |
|
26
|
1 |
|
$root = $builder->root('rpc'); |
|
27
|
1 |
|
$this->configureRouter($root->children()->arrayNode('router')); |
|
28
|
|
|
|
|
29
|
1 |
|
return $builder; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
private function configureRouter(ArrayNodeDefinition $root) |
|
33
|
|
|
{ |
|
34
|
1 |
|
$root->addDefaultsIfNotSet(); |
|
35
|
1 |
|
$root->treatNullLike(['endpoints' => []]); |
|
36
|
|
|
/** @var ArrayNodeDefinition $proto */ |
|
37
|
1 |
|
$endpoints = $root->children()->arrayNode('endpoints'); |
|
38
|
|
|
|
|
39
|
1 |
|
$proto = $endpoints->prototype('array'); |
|
40
|
|
|
|
|
41
|
1 |
|
$proto->append( |
|
42
|
1 |
|
(new ScalarNodeDefinition('path')) |
|
43
|
1 |
|
->isRequired() |
|
44
|
1 |
|
->example('/') |
|
45
|
1 |
|
->cannotBeEmpty() |
|
46
|
1 |
|
->info('Endpoint URI') |
|
47
|
1 |
|
); |
|
48
|
1 |
|
$proto->append( |
|
49
|
1 |
|
(new ArrayNodeDefinition('resources')) |
|
50
|
1 |
|
->beforeNormalization() |
|
51
|
1 |
|
->ifNull() |
|
52
|
1 |
|
->then( |
|
53
|
|
|
function () { |
|
54
|
|
|
return []; |
|
55
|
|
|
} |
|
56
|
1 |
|
) |
|
57
|
1 |
|
->ifString() |
|
58
|
1 |
|
->then( |
|
59
|
|
|
function ($v) { |
|
60
|
|
|
return [$v]; |
|
61
|
|
|
} |
|
62
|
1 |
|
) |
|
63
|
1 |
|
->end() |
|
64
|
1 |
|
->prototype('scalar')->end() |
|
65
|
1 |
|
->example('rpc.yml') |
|
66
|
1 |
|
->info('Route definitions') |
|
67
|
1 |
|
); |
|
68
|
1 |
|
$proto->append( |
|
69
|
1 |
|
(new VariableNodeDefinition('defaults')) |
|
70
|
1 |
|
); |
|
71
|
1 |
|
$proto->append( |
|
72
|
1 |
|
(new VariableNodeDefinition('context')) |
|
73
|
1 |
|
->beforeNormalization() |
|
74
|
1 |
|
->ifString() |
|
75
|
1 |
|
->then( |
|
76
|
1 |
|
function ($v) { |
|
77
|
1 |
|
return [$v]; |
|
78
|
|
|
} |
|
79
|
1 |
|
) |
|
80
|
1 |
|
->end() |
|
81
|
1 |
|
->defaultValue(['Default']) |
|
82
|
1 |
|
->info('Endpoint-wide context') |
|
83
|
1 |
|
->example(['Default']) |
|
84
|
1 |
|
); |
|
85
|
|
|
|
|
86
|
1 |
|
$endpoints->useAttributeAsKey('name'); |
|
87
|
1 |
|
$proto->addDefaultsIfNotSet(); |
|
88
|
1 |
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|