1313
1414use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
1515use Symfony \Component \Config \Definition \Builder \NodeBuilder ;
16+ use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
1617use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
1718use Symfony \Component \Config \Definition \ConfigurationInterface ;
1819use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
@@ -93,36 +94,6 @@ public function getConfigTreeBuilder()
9394 throw new InvalidConfigurationException ('You need to configure a proxy_client to get the cache_manager needed for invalidation handling. ' );
9495 })
9596 ->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 ()
12697 ->validate ()
12798 ->ifTrue (
12899 function ($ v ) {
@@ -314,81 +285,27 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
314285 ->children ()
315286 ->enumNode ('default ' )
316287 ->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. ' )
318289 ->end ()
319290 ->arrayNode ('varnish ' )
320- ->fixXmlConfig ('server ' )
321291 ->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 ('guzzle_client ' )
337- ->defaultNull ()
338- ->info ('Guzzle service to use for customizing the requests. ' )
339- ->end ()
292+ ->append ($ this ->getHttpDispatcherNode ())
340293 ->end ()
341294 ->end ()
342295
343296 ->arrayNode ('nginx ' )
344- ->fixXmlConfig ('server ' )
345297 ->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 ('guzzle_client ' )
361- ->defaultNull ()
362- ->info ('Guzzle service to use for customizing the requests. ' )
363- ->end ()
364298 ->scalarNode ('purge_location ' )
365- ->defaultValue ('' )
299+ ->defaultValue (false )
366300 ->info ('Path to trigger the purge on Nginx for different location purge. ' )
367301 ->end ()
302+ ->append ($ this ->getHttpDispatcherNode ())
368303 ->end ()
369304 ->end ()
370305
371306 ->arrayNode ('symfony ' )
372- ->fixXmlConfig ('server ' )
373307 ->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 ('guzzle_client ' )
389- ->defaultNull ()
390- ->info ('Guzzle service to use for customizing the requests. ' )
391- ->end ()
308+ ->append ($ this ->getHttpDispatcherNode ())
392309 ->end ()
393310 ->end ()
394311
@@ -397,6 +314,41 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
397314 ->end ();
398315 }
399316
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+
400352 private function addTestSection (ArrayNodeDefinition $ rootNode )
401353 {
402354 $ rootNode
@@ -432,37 +384,6 @@ private function addTestSection(ArrayNodeDefinition $rootNode)
432384 ->end ()
433385 ->end ()
434386 ->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 ()
466387 ->end ()
467388 ->end ()
468389 ->end ();
0 commit comments