|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of JSON RPC Client. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Igor Lazarev <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Strider2038\JsonRpcClient\Bridge\Symfony\DependencyInjection; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Igor Lazarev <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Configuration implements ConfigurationInterface |
|
22
|
|
|
{ |
|
23
|
8 |
|
public function getConfigTreeBuilder(): TreeBuilder |
|
24
|
|
|
{ |
|
25
|
8 |
|
$treeBuilder = new TreeBuilder('json_rpc_client'); |
|
26
|
8 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
27
|
|
|
|
|
28
|
|
|
$rootNode |
|
29
|
8 |
|
->performNoDeepMerging() |
|
|
|
|
|
|
30
|
8 |
|
->requiresAtLeastOneElement() |
|
31
|
8 |
|
->arrayPrototype() |
|
32
|
8 |
|
->children() |
|
33
|
8 |
|
->scalarNode('url') |
|
34
|
8 |
|
->info('Connection string to JSON RPC server, for example "http://localhost:1234"') |
|
35
|
8 |
|
->isRequired() |
|
36
|
8 |
|
->cannotBeEmpty() |
|
37
|
8 |
|
->end() |
|
38
|
8 |
|
->append($this->addOptionsNode()) |
|
39
|
8 |
|
->end() |
|
40
|
8 |
|
->end(); |
|
41
|
|
|
|
|
42
|
8 |
|
return $treeBuilder; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
8 |
|
private function addOptionsNode(): NodeDefinition |
|
46
|
|
|
{ |
|
47
|
8 |
|
$node = new ArrayNodeDefinition('options'); |
|
48
|
|
|
|
|
49
|
|
|
$node |
|
50
|
8 |
|
->children() |
|
51
|
8 |
|
->integerNode('request_timeout_us') |
|
52
|
8 |
|
->info('Request timeout in microseconds') |
|
53
|
8 |
|
->end() |
|
54
|
8 |
|
->booleanNode('enable_response_processing') |
|
|
|
|
|
|
55
|
8 |
|
->info('If enabled then successful responses will be unpacked and exceptions will be thrown on errors') |
|
56
|
8 |
|
->defaultTrue() |
|
57
|
8 |
|
->end() |
|
58
|
8 |
|
->append($this->addConnectionNode()) |
|
59
|
8 |
|
->enumNode('http_client_type') |
|
60
|
8 |
|
->info('Preferred HTTP client') |
|
61
|
8 |
|
->defaultValue('symfony') |
|
62
|
8 |
|
->values(['symfony', 'guzzle']) |
|
63
|
8 |
|
->end() |
|
64
|
8 |
|
->variableNode('transport_configuration') |
|
65
|
8 |
|
->end() |
|
66
|
8 |
|
->append($this->addSerializationNode()) |
|
67
|
8 |
|
->end(); |
|
68
|
|
|
|
|
69
|
8 |
|
return $node; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
8 |
|
private function addConnectionNode(): NodeDefinition |
|
73
|
|
|
{ |
|
74
|
8 |
|
$node = new ArrayNodeDefinition('connection'); |
|
75
|
|
|
|
|
76
|
|
|
$node |
|
77
|
8 |
|
->children() |
|
78
|
8 |
|
->integerNode('attempt_timeout_us') |
|
79
|
8 |
|
->info('Reconnection attempt timeout in microseconds. Must be greater than zero.') |
|
80
|
8 |
|
->end() |
|
81
|
8 |
|
->floatNode('timeout_multiplier') |
|
|
|
|
|
|
82
|
8 |
|
->info('Used to increase timeout value with growing reconnection attempts. Must be greater than 1.0.') |
|
83
|
8 |
|
->end() |
|
84
|
8 |
|
->integerNode('max_attempts') |
|
85
|
8 |
|
->info('Max sequential attempts to reconnect with remote server. Must be greater or equal to 1.') |
|
86
|
8 |
|
->end() |
|
87
|
8 |
|
->end(); |
|
88
|
|
|
|
|
89
|
8 |
|
return $node; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
8 |
|
private function addSerializationNode(): NodeDefinition |
|
93
|
|
|
{ |
|
94
|
8 |
|
$node = new ArrayNodeDefinition('serialization'); |
|
95
|
|
|
|
|
96
|
|
|
$node |
|
97
|
8 |
|
->children() |
|
98
|
8 |
|
->enumNode('serializer_type') |
|
99
|
8 |
|
->defaultValue('symfony') |
|
100
|
8 |
|
->values(['symfony', 'object', 'array']) |
|
101
|
8 |
|
->end() |
|
102
|
8 |
|
->arrayNode('result_types_by_methods') |
|
|
|
|
|
|
103
|
8 |
|
->defaultValue([]) |
|
104
|
8 |
|
->scalarPrototype()->end() |
|
105
|
8 |
|
->end() |
|
106
|
8 |
|
->scalarNode('default_error_type') |
|
107
|
8 |
|
->end() |
|
108
|
8 |
|
->arrayNode('error_types_by_methods') |
|
109
|
8 |
|
->defaultValue([]) |
|
110
|
8 |
|
->scalarPrototype()->end() |
|
111
|
8 |
|
->end() |
|
112
|
8 |
|
->end(); |
|
113
|
|
|
|
|
114
|
8 |
|
return $node; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|