1 | <?php |
||
20 | class Configuration implements ConfigurationInterface |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 7 | public function getConfigTreeBuilder() |
|
26 | { |
||
27 | 7 | $treeBuilder = new TreeBuilder(); |
|
28 | 7 | $rootNode = $treeBuilder->root('httplug'); |
|
29 | |||
30 | 7 | $this->configureClients($rootNode); |
|
31 | 7 | $this->configurePlugins($rootNode); |
|
32 | |||
33 | $rootNode |
||
34 | 7 | ->validate() |
|
35 | ->ifTrue(function ($v) { |
||
36 | 6 | return !empty($v['classes']['client']) |
|
37 | 6 | || !empty($v['classes']['message_factory']) |
|
38 | 3 | || !empty($v['classes']['uri_factory']) |
|
39 | 6 | || !empty($v['classes']['stream_factory']); |
|
40 | 7 | }) |
|
41 | ->then(function ($v) { |
||
42 | 3 | foreach ($v['classes'] as $key => $class) { |
|
43 | 3 | if (null !== $class && !class_exists($class)) { |
|
44 | 1 | throw new InvalidConfigurationException(sprintf( |
|
45 | 1 | 'Class %s specified for httplug.classes.%s does not exist.', |
|
46 | 1 | $class, |
|
47 | $key |
||
48 | 1 | )); |
|
49 | } |
||
50 | 2 | } |
|
51 | |||
52 | 2 | return $v; |
|
53 | 7 | }) |
|
54 | 7 | ->end() |
|
55 | 7 | ->children() |
|
56 | 7 | ->arrayNode('main_alias') |
|
57 | 7 | ->addDefaultsIfNotSet() |
|
58 | 7 | ->info('Configure which service the main alias point to.') |
|
59 | 7 | ->children() |
|
60 | 7 | ->scalarNode('client')->defaultValue('httplug.client.default')->end() |
|
61 | 7 | ->scalarNode('message_factory')->defaultValue('httplug.message_factory.default')->end() |
|
62 | 7 | ->scalarNode('uri_factory')->defaultValue('httplug.uri_factory.default')->end() |
|
63 | 7 | ->scalarNode('stream_factory')->defaultValue('httplug.stream_factory.default')->end() |
|
64 | 7 | ->end() |
|
65 | 7 | ->end() |
|
66 | 7 | ->arrayNode('classes') |
|
67 | 7 | ->addDefaultsIfNotSet() |
|
68 | 7 | ->info('Overwrite a service class instead of using the discovery mechanism.') |
|
69 | 7 | ->children() |
|
70 | 7 | ->scalarNode('client')->defaultNull()->end() |
|
71 | 7 | ->scalarNode('message_factory')->defaultNull()->end() |
|
72 | 7 | ->scalarNode('uri_factory')->defaultNull()->end() |
|
73 | 7 | ->scalarNode('stream_factory')->defaultNull()->end() |
|
74 | 7 | ->end() |
|
75 | 7 | ->end() |
|
76 | 7 | ->arrayNode('toolbar') |
|
77 | 7 | ->addDefaultsIfNotSet() |
|
78 | 7 | ->info('Extend the debug profiler with inforation about requests.') |
|
79 | 7 | ->children() |
|
80 | 7 | ->enumNode('enabled') |
|
81 | 7 | ->info('If "auto" (default), the toolbar is activated when kernel.debug is true. You can force the toolbar on and off by changing this option.') |
|
82 | 7 | ->values([true, false, 'auto']) |
|
83 | 7 | ->defaultValue('auto') |
|
84 | 7 | ->end() |
|
85 | 7 | ->scalarNode('formatter')->defaultNull()->end() |
|
86 | 7 | ->scalarNode('captured_body_length') |
|
87 | 7 | ->defaultValue(0) |
|
88 | 7 | ->canNotBeEmpty() |
|
89 | 7 | ->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. Only available with the default formatter (FullHttpMessageFormatter).') |
|
90 | 7 | ->end() |
|
91 | 7 | ->end() |
|
92 | 7 | ->end() |
|
93 | 7 | ->arrayNode('discovery') |
|
94 | 7 | ->addDefaultsIfNotSet() |
|
95 | 7 | ->info('Control what clients should be found by the discovery.') |
|
96 | 7 | ->children() |
|
97 | 7 | ->scalarNode('client') |
|
98 | 7 | ->defaultValue('auto') |
|
99 | 7 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
100 | 7 | ->end() |
|
101 | 7 | ->scalarNode('async_client') |
|
102 | 7 | ->defaultNull() |
|
103 | 7 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
104 | 7 | ->end() |
|
105 | 7 | ->end() |
|
106 | 7 | ->end() |
|
107 | 7 | ->end(); |
|
108 | |||
109 | 7 | return $treeBuilder; |
|
110 | } |
||
111 | |||
112 | 7 | protected function configureClients(ArrayNodeDefinition $root) |
|
113 | { |
||
114 | 7 | $root->children() |
|
115 | 7 | ->arrayNode('clients') |
|
116 | 7 | ->validate() |
|
117 | ->ifTrue(function ($clients) { |
||
118 | foreach ($clients as $name => $config) { |
||
119 | return $config['flexible_client'] && $config['http_methods_client']; |
||
120 | } |
||
121 | |||
122 | return false; |
||
123 | 7 | }) |
|
124 | 7 | ->thenInvalid('A http client can\'t be decorated with both FlexibleHttpClient and HttpMethodsClient. Only one of the following options can be true. ("flexible_client", "http_methods_client")')->end() |
|
125 | 7 | ->useAttributeAsKey('name') |
|
126 | 7 | ->prototype('array') |
|
127 | 7 | ->children() |
|
128 | 7 | ->scalarNode('factory') |
|
129 | 7 | ->isRequired() |
|
130 | 7 | ->cannotBeEmpty() |
|
131 | 7 | ->info('The service id of a factory to use when creating the adapter.') |
|
132 | 7 | ->end() |
|
133 | 7 | ->booleanNode('flexible_client') |
|
134 | 7 | ->defaultFalse() |
|
135 | 7 | ->info('Set to true to get the client wrapped in a FlexibleHttpClient which emulates async or sync behavior.') |
|
136 | 7 | ->end() |
|
137 | 7 | ->booleanNode('http_methods_client') |
|
138 | 7 | ->defaultFalse() |
|
139 | 7 | ->info('Set to true to get the client wrapped in a HttpMethodsClient which emulates provides functions for HTTP verbs.') |
|
140 | 7 | ->end() |
|
141 | 7 | ->arrayNode('plugins') |
|
142 | 7 | ->info('A list of service ids of plugins. The order is important.') |
|
143 | 7 | ->prototype('scalar')->end() |
|
144 | 7 | ->end() |
|
145 | 7 | ->variableNode('config')->defaultValue([])->end() |
|
146 | 7 | ->end() |
|
147 | 7 | ->end(); |
|
148 | 7 | } |
|
149 | |||
150 | /** |
||
151 | * @param ArrayNodeDefinition $root |
||
152 | */ |
||
153 | 7 | protected function configurePlugins(ArrayNodeDefinition $root) |
|
264 | |||
265 | /** |
||
266 | * Add configuration for authentication plugin. |
||
267 | * |
||
268 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
269 | */ |
||
270 | 7 | private function addAuthenticationPluiginNode() |
|
314 | |||
315 | /** |
||
316 | * Validate that the configuration fragment has the specified keys and none other. |
||
317 | * |
||
318 | * @param array $expected Fields that must exist |
||
319 | * @param array $actual Actual configuration hashmap |
||
320 | * @param string $authName Name of authentication method for error messages |
||
321 | * |
||
322 | * @throws InvalidConfigurationException If $actual does not have exactly the keys specified in $expected (plus 'type') |
||
323 | */ |
||
324 | 2 | private function validateAuthenticationType(array $expected, array $actual, $authName) |
|
342 | } |
||
343 |