13
13
14
14
use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
15
15
use Symfony \Component \Config \Definition \Builder \NodeBuilder ;
16
+ use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
16
17
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
17
18
use Symfony \Component \Config \Definition \ConfigurationInterface ;
18
19
use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
@@ -93,36 +94,6 @@ public function getConfigTreeBuilder()
93
94
throw new InvalidConfigurationException ('You need to configure a proxy_client to get the cache_manager needed for invalidation handling. ' );
94
95
})
95
96
->end ()
96
- ->validate ()
97
- ->ifTrue (function ($ v ) {
98
- return isset ($ v ['test ' ])
99
- && $ v ['test ' ]['client ' ]['varnish ' ]['enabled ' ]
100
- && !isset ($ v ['proxy_client ' ]['varnish ' ]);
101
- })
102
- ->then (function ($ v ) {
103
- if ('auto ' === $ v ['test ' ]['client ' ]['varnish ' ]['enabled ' ]) {
104
- $ v ['test ' ]['client ' ]['varnish ' ]['enabled ' ] = false ;
105
-
106
- return $ v ;
107
- }
108
- throw new InvalidConfigurationException ('You need to configure the Varnish proxy_client to use the Varnish test client ' );
109
- })
110
- ->end ()
111
- ->validate ()
112
- ->ifTrue (function ($ v ) {
113
- if (isset ($ v ['test ' ])) {
114
- return $ v ['test ' ]['client ' ]['nginx ' ]['enabled ' ] && !isset ($ v ['proxy_client ' ]['nginx ' ]);
115
- }
116
- })
117
- ->then (function ($ v ) {
118
- if ('auto ' === $ v ['test ' ]['client ' ]['nginx ' ]['enabled ' ]) {
119
- $ v ['test ' ]['client ' ]['nginx ' ]['enabled ' ] = false ;
120
-
121
- return $ v ;
122
- }
123
- throw new InvalidConfigurationException ('You need to configure the Nginx proxy_client to use the Nginx test client ' );
124
- })
125
- ->end ()
126
97
->validate ()
127
98
->ifTrue (
128
99
function ($ v ) {
@@ -314,81 +285,27 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
314
285
->children ()
315
286
->enumNode ('default ' )
316
287
->values (array ('varnish ' , 'nginx ' , 'symfony ' ))
317
- ->info ('If you configure more than one proxy client, specify which client is the default. ' )
288
+ ->info ('If you configure more than one proxy client, you need to specify which client is the default. ' )
318
289
->end ()
319
290
->arrayNode ('varnish ' )
320
- ->fixXmlConfig ('server ' )
321
291
->children ()
322
- ->arrayNode ('servers ' )
323
- ->beforeNormalization ()->ifString ()->then (function ($ v ) {
324
- return preg_split ('/\s*,\s*/ ' , $ v );
325
- })->end ()
326
- ->useAttributeAsKey ('name ' )
327
- ->isRequired ()
328
- ->requiresAtLeastOneElement ()
329
- ->prototype ('scalar ' )->end ()
330
- ->info ('Addresses of the hosts Varnish is running on. May be hostname or ip, and with :port if not the default port 80. ' )
331
- ->end ()
332
- ->scalarNode ('base_url ' )
333
- ->defaultNull ()
334
- ->info ('Default host name and optional path for path based invalidation. ' )
335
- ->end ()
336
- ->scalarNode ('http_client ' )
337
- ->defaultValue ('httplug.client ' )
338
- ->info ('Httplug service to use for sending the requests. ' )
339
- ->end ()
292
+ ->append ($ this ->getHttpDispatcherNode ())
340
293
->end ()
341
294
->end ()
342
295
343
296
->arrayNode ('nginx ' )
344
- ->fixXmlConfig ('server ' )
345
297
->children ()
346
- ->arrayNode ('servers ' )
347
- ->beforeNormalization ()->ifString ()->then (function ($ v ) {
348
- return preg_split ('/\s*,\s*/ ' , $ v );
349
- })->end ()
350
- ->useAttributeAsKey ('name ' )
351
- ->isRequired ()
352
- ->requiresAtLeastOneElement ()
353
- ->prototype ('scalar ' )->end ()
354
- ->info ('Addresses of the hosts Nginx is running on. May be hostname or ip, and with :port if not the default port 80. ' )
355
- ->end ()
356
- ->scalarNode ('base_url ' )
357
- ->defaultNull ()
358
- ->info ('Default host name and optional path for path based invalidation. ' )
359
- ->end ()
360
- ->scalarNode ('http_client ' )
361
- ->defaultValue ('httplug.client ' )
362
- ->info ('Httplug service to use for sending the requests. ' )
363
- ->end ()
364
298
->scalarNode ('purge_location ' )
365
- ->defaultValue ('' )
299
+ ->defaultValue (false )
366
300
->info ('Path to trigger the purge on Nginx for different location purge. ' )
367
301
->end ()
302
+ ->append ($ this ->getHttpDispatcherNode ())
368
303
->end ()
369
304
->end ()
370
305
371
306
->arrayNode ('symfony ' )
372
- ->fixXmlConfig ('server ' )
373
307
->children ()
374
- ->arrayNode ('servers ' )
375
- ->beforeNormalization ()->ifString ()->then (function ($ v ) {
376
- return preg_split ('/\s*,\s*/ ' , $ v );
377
- })->end ()
378
- ->useAttributeAsKey ('name ' )
379
- ->isRequired ()
380
- ->requiresAtLeastOneElement ()
381
- ->prototype ('scalar ' )->end ()
382
- ->info ('Addresses of the hosts Symfony HttpCache is running on. May be hostname or ip, and with :port if not the default port 80. ' )
383
- ->end ()
384
- ->scalarNode ('base_url ' )
385
- ->defaultNull ()
386
- ->info ('Default host name and optional path for path based invalidation. ' )
387
- ->end ()
388
- ->scalarNode ('http_client ' )
389
- ->defaultValue ('httplug.client ' )
390
- ->info ('httplug service to use for sending the requests. ' )
391
- ->end ()
308
+ ->append ($ this ->getHttpDispatcherNode ())
392
309
->end ()
393
310
->end ()
394
311
@@ -397,6 +314,41 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
397
314
->end ();
398
315
}
399
316
317
+ /**
318
+ * Get the configuration node for a HTTP dispatcher in a proxy client.
319
+ *
320
+ * @return NodeDefinition
321
+ */
322
+ private function getHttpDispatcherNode ()
323
+ {
324
+ $ treeBuilder = new TreeBuilder ();
325
+ $ node = $ treeBuilder ->root ('http ' );
326
+
327
+ $ node
328
+ ->fixXmlConfig ('server ' )
329
+ ->isRequired ()
330
+ ->children ()
331
+ ->arrayNode ('servers ' )
332
+ ->info ('Addresses of the hosts the caching proxy is running on. May be hostname or ip, and with :port if not the default port 80. ' )
333
+ ->useAttributeAsKey ('name ' )
334
+ ->isRequired ()
335
+ ->requiresAtLeastOneElement ()
336
+ ->prototype ('scalar ' )->end ()
337
+ ->end ()
338
+ ->scalarNode ('base_url ' )
339
+ ->defaultNull ()
340
+ ->info ('Default host name and optional path for path based invalidation. ' )
341
+ ->end ()
342
+ ->scalarNode ('http_client ' )
343
+ ->defaultNull ()
344
+ ->info ('Httplug async client service name to use for sending the requests. ' )
345
+ ->end ()
346
+ ->end ()
347
+ ;
348
+
349
+ return $ node ;
350
+ }
351
+
400
352
private function addTestSection (ArrayNodeDefinition $ rootNode )
401
353
{
402
354
$ rootNode
@@ -432,37 +384,6 @@ private function addTestSection(ArrayNodeDefinition $rootNode)
432
384
->end ()
433
385
->end ()
434
386
->end ()
435
- ->arrayNode ('client ' )
436
- ->addDefaultsIfNotSet ()
437
- ->children ()
438
- ->enumNode ('default ' )
439
- ->values (array ('varnish ' , 'nginx ' ))
440
- ->info ('If you configure more than one proxy client, specify which client is the default. ' )
441
- ->end ()
442
- ->arrayNode ('varnish ' )
443
- ->addDefaultsIfNotSet ()
444
- ->canBeEnabled ()
445
- ->children ()
446
- ->enumNode ('enabled ' )
447
- ->values (array (true , false , 'auto ' ))
448
- ->defaultValue ('auto ' )
449
- ->info ('Whether to enable the Varnish test client. ' )
450
- ->end ()
451
- ->end ()
452
- ->end ()
453
- ->arrayNode ('nginx ' )
454
- ->addDefaultsIfNotSet ()
455
- ->canBeEnabled ()
456
- ->children ()
457
- ->enumNode ('enabled ' )
458
- ->values (array (true , false , 'auto ' ))
459
- ->defaultValue ('auto ' )
460
- ->info ('Whether to enable the Nginx test client. ' )
461
- ->end ()
462
- ->end ()
463
- ->end ()
464
- ->end ()
465
- ->end ()
466
387
->end ()
467
388
->end ()
468
389
->end ();
0 commit comments