Skip to content

Commit adbb4a4

Browse files
committed
cleanup tests and drop some unused things
1 parent 88abe26 commit adbb4a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+397
-685
lines changed

CHANGELOG.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ Changelog
44
2.0.0 (unreleased)
55
------------------
66

7-
* [User Context] Added an option always_vary_on_context_hash to make it
8-
possible to disable automatically setting the vary headers for the user
7+
* [Proxy Client Configuration] The configuration for the proxy client has been
8+
adjusted. Proxy servers are now configured under `http` and `servers` must be
9+
a list - a comma separated string of server IPs is no longer supported.
10+
11+
* [User Context] Added an option always_vary_on_context_hash to make it
12+
possible to disable automatically setting the vary headers for the user
913
hash.
1014

11-
* [Event Listeners] Renamed the event listener classes to XxxLlistener
15+
* [Event Listeners] Renamed the event listener classes to XxxLlistener.
1216

1317
* Updated the version of FOSHttpCache to 2.*. See [FOSHttpCache changelog]
1418
(https://github.com/FriendsOfSymfony/FOSHttpCache/blob/master/CHANGELOG.md).
1519
Most important, there is no more hard coupling on Guzzle HTTP client. We now
16-
use the HTTPlug HTTP client abstraction. You now need to explicitly specify
17-
the adapter you want, see [installation instructions]
20+
use the HTTPlug HTTP client abstraction. Your composer.json now needs to
21+
specify which HTTP client to install, see [installation instructions]
1822
(http://foshttpcachebundle.readthedocs.org/en/stable/installation.html)
19-
Deprecated methods have been removed.
23+
24+
* [Tags] The TagHandler has been split. Invalidating tags happens through the
25+
CacheManager (if you use annotations for tag invalidation, you don't need to
26+
change anything). Recording tags and writing them into the responses is done
27+
through the SymfonyResponseTagger now.
28+
29+
* [Test] Dropped the proxy client services as they where not used anywhere. The
30+
services `fos_http_cache.test.client.varnish` and `fos_http_cache.test.client.nginx`
31+
no longer exist.
32+
33+
* Deprecated methods have been removed.
2034

2135
1.3.7
2236
-----

Command/InvalidateTagCommand.php

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Input\InputArgument;
19-
use FOS\HttpCache\Handler\TagHandler;
2019

2120
/**
2221
* A command to trigger cache invalidation by tag from the command line.
@@ -26,39 +25,18 @@
2625
class InvalidateTagCommand extends ContainerAwareCommand
2726
{
2827
/**
29-
* @var TagHandler
28+
* @var CacheManager
3029
*/
31-
private $tagHandler;
30+
private $cacheManager;
3231

3332
/**
3433
* @var string
3534
*/
3635
private $commandName;
3736

38-
/**
39-
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
40-
* is automatically loaded.
41-
*
42-
* Passing CacheManager as argument is deprecated and will be restricted to TagHandler in 2.0.
43-
*
44-
* @param TagHandler|CacheManager|null $tagHandler The tag handler to talk to
45-
* @param string $commandName Name of this command, in case you want to reuse it
46-
*/
47-
public function __construct($tagHandler = null, $commandName = 'fos:httpcache:invalidate:tag')
37+
public function __construct(CacheManager $cacheManager)
4838
{
49-
if (!($tagHandler instanceof TagHandler || $tagHandler instanceof CacheManager || null === $tagHandler)) {
50-
throw new \InvalidArgumentException(
51-
sprintf(
52-
'Expected instance of TagHandler, CacheManager or null, but got %s',
53-
get_class($tagHandler)
54-
)
55-
);
56-
}
57-
if ($tagHandler instanceof CacheManager) {
58-
@trigger_error('Passing the CacheManager to '.__CLASS__.' is deprecated since version 1.2 and will be removed in 2.0. Provide the TagHandler instead.', E_USER_DEPRECATED);
59-
}
60-
$this->commandName = $commandName;
61-
$this->tagHandler = $tagHandler;
39+
$this->cacheManager = $cacheManager;
6240
parent::__construct();
6341
}
6442

@@ -68,7 +46,7 @@ public function __construct($tagHandler = null, $commandName = 'fos:httpcache:in
6846
protected function configure()
6947
{
7048
$this
71-
->setName($this->commandName)
49+
->setName('fos:httpcache:invalidate:tag')
7250
->setDescription('Invalidate cached content matching the specified tags on all configured caching proxies')
7351
->addArgument(
7452
'tags',
@@ -93,18 +71,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
9371
{
9472
$tags = $input->getArgument('tags');
9573

96-
$this->getTagManager()->invalidateTags($tags);
97-
}
98-
99-
/**
100-
* @return TagHandler|CacheManager
101-
*/
102-
protected function getTagManager()
103-
{
104-
if (!$this->tagHandler) {
105-
$this->tagHandler = $this->getContainer()->get('fos_http_cache.handler.tag_handler');
106-
}
107-
108-
return $this->tagHandler;
109-
}
110-
}
74+
$this->cacheManager->invalidateTags($tags);
75+
}}

DependencyInjection/Configuration.php

Lines changed: 41 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1515
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
16+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1617
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1718
use Symfony\Component\Config\Definition\ConfigurationInterface;
1819
use 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('http_client')
337-
->defaultValue('httplug.client')
338-
->info('Httplug service to use for sending 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('http_client')
361-
->defaultValue('httplug.client')
362-
->info('Httplug service to use for sending 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('http_client')
389-
->defaultValue('httplug.client')
390-
->info('httplug service to use for sending 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

Comments
 (0)