1 | <?php |
||
20 | class Configuration implements ConfigurationInterface |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 7 | public function getConfigTreeBuilder() |
|
92 | |||
93 | 7 | protected function configureClients(ArrayNodeDefinition $root) |
|
94 | { |
||
95 | 7 | $root->children() |
|
96 | 7 | ->arrayNode('clients') |
|
97 | 7 | ->validate() |
|
98 | 7 | ->ifTrue(function($clients) { |
|
99 | 7 | foreach ($clients as $name => $config) { |
|
100 | 7 | return $config['flexible_client'] && $config['http_methods_client']; |
|
101 | 7 | } |
|
102 | 7 | return false; |
|
103 | 7 | }) |
|
104 | 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() |
|
105 | 7 | ->useAttributeAsKey('name') |
|
106 | 7 | ->prototype('array') |
|
107 | 7 | ->children() |
|
108 | 7 | ->scalarNode('factory') |
|
109 | 7 | ->isRequired() |
|
110 | 7 | ->cannotBeEmpty() |
|
111 | 7 | ->info('The service id of a factory to use when creating the adapter.') |
|
112 | 7 | ->end() |
|
113 | ->booleanNode('flexible_client') |
||
114 | ->defaultFalse() |
||
115 | ->info('Set to true to get the client wrapped in a FlexibleHttpClient which emulates async or sync behavior.') |
||
116 | ->end() |
||
117 | 7 | ->booleanNode('http_methods_client') |
|
118 | ->defaultFalse() |
||
119 | 7 | ->info('Set to true to get the client wrapped in a HttpMethodsClient which emulates provides functions for HTTP verbs.') |
|
120 | 7 | ->end() |
|
121 | 7 | ->arrayNode('plugins') |
|
122 | 7 | ->info('A list of service ids of plugins. The order is important.') |
|
123 | 7 | ->prototype('scalar')->end() |
|
124 | ->end() |
||
125 | 7 | ->variableNode('config')->defaultValue([])->end() |
|
126 | 7 | ->end() |
|
127 | 7 | ->end(); |
|
128 | 7 | } |
|
129 | 7 | ||
130 | 7 | /** |
|
131 | 7 | * @param ArrayNodeDefinition $root |
|
132 | 7 | */ |
|
133 | 7 | protected function configurePlugins(ArrayNodeDefinition $root) |
|
134 | 7 | { |
|
135 | 7 | $root->children() |
|
136 | 7 | ->arrayNode('plugins') |
|
137 | 7 | ->addDefaultsIfNotSet() |
|
138 | 7 | ->children() |
|
139 | 7 | ->append($this->addAuthenticationPluiginNode()) |
|
140 | 7 | ||
141 | 7 | ->arrayNode('cache') |
|
142 | 7 | ->canBeEnabled() |
|
143 | 7 | ->addDefaultsIfNotSet() |
|
144 | 7 | ->children() |
|
145 | 7 | ->scalarNode('cache_pool') |
|
146 | 7 | ->info('This must be a service id to a service implementing Psr\Cache\CacheItemPoolInterface') |
|
147 | 7 | ->isRequired() |
|
148 | ->cannotBeEmpty() |
||
149 | 7 | ->end() |
|
150 | 7 | ->scalarNode('stream_factory') |
|
151 | 7 | ->info('This must be a service id to a service implementing Http\Message\StreamFactory') |
|
152 | 7 | ->defaultValue('httplug.stream_factory') |
|
153 | 7 | ->cannotBeEmpty() |
|
154 | 7 | ->end() |
|
155 | 7 | ->arrayNode('config') |
|
156 | 7 | ->addDefaultsIfNotSet() |
|
157 | 7 | ->children() |
|
158 | 7 | ->scalarNode('default_ttl')->defaultNull()->end() |
|
159 | ->scalarNode('respect_cache_headers')->defaultTrue()->end() |
||
160 | 7 | ->end() |
|
161 | 7 | ->end() |
|
162 | 7 | ->end() |
|
163 | 7 | ->end() // End cache plugin |
|
164 | 7 | ||
165 | 7 | ->arrayNode('cookie') |
|
166 | 7 | ->canBeEnabled() |
|
167 | ->children() |
||
168 | 7 | ->scalarNode('cookie_jar') |
|
169 | 7 | ->info('This must be a service id to a service implementing Http\Message\CookieJar') |
|
170 | 7 | ->isRequired() |
|
171 | 7 | ->cannotBeEmpty() |
|
172 | 7 | ->end() |
|
173 | 7 | ->end() |
|
174 | 7 | ->end() // End cookie plugin |
|
175 | 7 | ||
176 | 7 | ->arrayNode('decoder') |
|
177 | 7 | ->canBeDisabled() |
|
178 | ->addDefaultsIfNotSet() |
||
179 | 7 | ->children() |
|
180 | 7 | ->scalarNode('use_content_encoding')->defaultTrue()->end() |
|
181 | 7 | ->end() |
|
182 | 7 | ->end() // End decoder plugin |
|
183 | 7 | ||
184 | 7 | ->arrayNode('history') |
|
185 | 7 | ->canBeEnabled() |
|
186 | 7 | ->children() |
|
187 | 7 | ->scalarNode('journal') |
|
188 | 7 | ->info('This must be a service id to a service implementing Http\Client\Plugin\Journal') |
|
189 | 7 | ->isRequired() |
|
190 | 7 | ->cannotBeEmpty() |
|
191 | 7 | ->end() |
|
192 | 7 | ->end() |
|
193 | 7 | ->end() // End history plugin |
|
194 | |||
195 | 7 | ->arrayNode('logger') |
|
196 | 7 | ->canBeDisabled() |
|
197 | 7 | ->addDefaultsIfNotSet() |
|
198 | 7 | ->children() |
|
199 | 7 | ->scalarNode('logger') |
|
200 | 7 | ->info('This must be a service id to a service implementing Psr\Log\LoggerInterface') |
|
201 | 7 | ->defaultValue('logger') |
|
202 | 7 | ->cannotBeEmpty() |
|
203 | ->end() |
||
204 | 7 | ->scalarNode('formatter') |
|
205 | 7 | ->info('This must be a service id to a service implementing Http\Message\Formatter') |
|
206 | 7 | ->defaultNull() |
|
207 | 7 | ->end() |
|
208 | 7 | ->end() |
|
209 | 7 | ->end() // End logger plugin |
|
210 | 7 | ||
211 | ->arrayNode('redirect') |
||
212 | 7 | ->canBeDisabled() |
|
213 | 7 | ->addDefaultsIfNotSet() |
|
214 | 7 | ->children() |
|
215 | 7 | ->scalarNode('preserve_header')->defaultTrue()->end() |
|
216 | 7 | ->scalarNode('use_default_for_multiple')->defaultTrue()->end() |
|
217 | 7 | ->end() |
|
218 | 7 | ->end() // End redirect plugin |
|
219 | 7 | ||
220 | 7 | ->arrayNode('retry') |
|
221 | 7 | ->canBeDisabled() |
|
222 | 7 | ->addDefaultsIfNotSet() |
|
223 | ->children() |
||
224 | 7 | ->scalarNode('retry')->defaultValue(1)->end() |
|
225 | 7 | ->end() |
|
226 | 7 | ->end() // End retry plugin |
|
227 | 7 | ||
228 | ->arrayNode('stopwatch') |
||
229 | ->canBeDisabled() |
||
230 | ->addDefaultsIfNotSet() |
||
231 | ->children() |
||
232 | ->scalarNode('stopwatch') |
||
233 | ->info('This must be a service id to a service extending Symfony\Component\Stopwatch\Stopwatch') |
||
234 | 7 | ->defaultValue('debug.stopwatch') |
|
235 | ->cannotBeEmpty() |
||
236 | 7 | ->end() |
|
237 | 7 | ->end() |
|
238 | ->end() // End stopwatch plugin |
||
239 | 7 | ||
240 | 7 | ->end() |
|
241 | 7 | ->end() |
|
242 | 7 | ->end(); |
|
243 | 7 | } |
|
244 | 2 | ||
245 | 2 | /** |
|
246 | 1 | * Add configuration for authentication plugin. |
|
247 | 1 | * |
|
248 | 2 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
|
249 | 1 | */ |
|
250 | 1 | private function addAuthenticationPluiginNode() |
|
294 | |||
295 | 2 | /** |
|
296 | 1 | * Validate that the configuration fragment has the specified keys and none other. |
|
297 | * |
||
298 | * @param array $expected Fields that must exist |
||
299 | 1 | * @param array $actual Actual configuration hashmap |
|
300 | 1 | * @param string $authName Name of authentication method for error messages |
|
301 | 1 | * |
|
302 | 1 | * @throws InvalidConfigurationException If $actual does not have exactly the keys specified in $expected (plus 'type') |
|
303 | 1 | */ |
|
304 | 1 | private function validateAuthenticationType(array $expected, array $actual, $authName) |
|
322 | } |
||
323 |