Skip to content

Commit e5161c3

Browse files
committed
Merge bundles (close #3)
Merge composer.json Merge configuration Merge PHPUnit config Create separate installation doc Change namespace to FOS Support Symfony 2.4 and drop 2.1/2.2 support Remove cURL check Fix search/replace mistake Fix typo Make contributors homepage URL forwards-compatible
1 parent 73c3fe6 commit e5161c3

37 files changed

+350
-557
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ language: php
33
php:
44
- 5.3
55
- 5.4
6+
- 5.5
7+
8+
env:
9+
- SYMFONY_VERSION=2.3.*
10+
- SYMFONY_VERSION=2.4.*
11+
- SYMFONY_VERSION=dev-master
612

713
before_script:
8-
- composer install --dev
14+
- composer require symfony/framework-bundle:${SYMFONY_VERSION}
915

1016
script: phpunit --coverage-text

CacheManager.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Driebit\HttpCacheBundle;
3+
namespace FOS\HttpCacheBundle;
44

5-
use Driebit\HttpCacheBundle\HttpCache\HttpCacheInterface;
5+
use FOS\HttpCacheBundle\HttpCache\HttpCacheInterface;
66
use Symfony\Component\Routing\RouterInterface;
77

88
/**
@@ -47,9 +47,9 @@ public function __construct(HttpCacheInterface $cache, RouterInterface $router)
4747
*
4848
* @return $this
4949
*/
50-
public function invalidatePath($path)
50+
public function invalidatePath($path, array $headers = array())
5151
{
52-
$this->invalidationQueue[$path] = $path;
52+
$this->invalidationQueue[$path] = $headers;
5353

5454
return $this;
5555
}
@@ -69,6 +69,19 @@ public function invalidateRoute($name, $parameters = array())
6969
return $this;
7070
}
7171

72+
public function refreshPath($path, $headers)
73+
{
74+
$headers = array("Cache-Control: no-cache, no-store, max-age=0, must-revalidate");
75+
76+
}
77+
78+
79+
80+
public function invalidateRegex($regex)
81+
{
82+
83+
}
84+
7285
/**
7386
* Flush all paths queued for invalidation
7487
*

DependencyInjection/Configuration.php

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace Driebit\HttpCacheBundle\DependencyInjection;
3+
namespace FOS\HttpCacheBundle\DependencyInjection;
44

5+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
56
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
67
use Symfony\Component\Config\Definition\ConfigurationInterface;
78

@@ -18,24 +19,116 @@ class Configuration implements ConfigurationInterface
1819
public function getConfigTreeBuilder()
1920
{
2021
$treeBuilder = new TreeBuilder();
21-
$rootNode = $treeBuilder->root('driebit_http_cache');
22+
$rootNode = $treeBuilder->root('fos_http_cache');
2223

2324
$rootNode
2425
->children()
25-
->arrayNode('http_cache')->isRequired()
26-
->children()
27-
->arrayNode('varnish')
28-
->children()
29-
->scalarNode('host')->isRequired()->end()
30-
->arrayNode('ips')
31-
->isRequired()
32-
->requiresAtLeastOneElement()
33-
->prototype('scalar')->end()
34-
->end()
26+
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
27+
->booleanNode('authorization_listener')->defaultFalse()->end()
28+
->end()
29+
;
30+
31+
$this->addRulesSection($rootNode);
32+
$this->addVarnishSection($rootNode);
33+
$this->addFlashMessageListenerSection($rootNode);
34+
$this->addInvalidatorsSection($rootNode);
35+
36+
return $treeBuilder;
37+
}
38+
39+
private function addRulesSection(ArrayNodeDefinition $rootNode)
40+
{
41+
$rootNode
42+
->fixXmlConfig('rule', 'rules')
43+
->children()
44+
->arrayNode('rules')
45+
->cannotBeOverwritten()
46+
->prototype('array')
47+
->children()
48+
->scalarNode('unless_role')->defaultNull()->end()
49+
->scalarNode('path')->defaultNull()->info('URL path info')->end()
50+
->arrayNode('method')
51+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
52+
->useAttributeAsKey('name')
53+
->prototype('scalar')->end()
54+
->info('HTTP method')
55+
->end()
56+
->arrayNode('ips')
57+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
58+
->useAttributeAsKey('name')
59+
->prototype('scalar')->end()
60+
->info('List of ips')
61+
->end()
62+
->arrayNode('attributes')
63+
->addDefaultsIfNotSet()
64+
->cannotBeEmpty()
65+
->treatNullLike(array())
66+
->info('Request attributes')
67+
->end()
68+
->scalarNode('domain')->defaultNull()->info('depreciated, use host instead')->end()
69+
->scalarNode('host')->defaultNull()->info('URL host name')->end()
70+
->scalarNode('controller')->defaultNull()->info('controller action name')->end()
71+
->scalarNode('reverse_proxy_ttl')->defaultNull()->end()
72+
->arrayNode('controls')
73+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
74+
->useAttributeAsKey('name')
75+
->prototype('scalar')->end()
76+
->end()
77+
->arrayNode('vary')
78+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
79+
->prototype('scalar')->end()
3580
->end()
3681
->end()
3782
->end()
3883
->end()
84+
->end();
85+
}
86+
87+
private function addVarnishSection(ArrayNodeDefinition $rootNode)
88+
{
89+
$rootNode
90+
->children()
91+
->arrayNode('varnish')
92+
->children()
93+
->arrayNode('ips')
94+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
95+
->useAttributeAsKey('name')
96+
->isRequired()
97+
->requiresAtLeastOneElement()
98+
->prototype('scalar')->end()
99+
->end()
100+
->scalarNode('host')->defaultNull()->info('Default host name')->end()
101+
->end()
102+
->end()
103+
->end();
104+
}
105+
106+
private function addFlashMessageListenerSection(ArrayNodeDefinition $rootNode)
107+
{
108+
$rootNode
109+
->children()
110+
->arrayNode('flash_message_listener')
111+
->canBeUnset()
112+
->treatFalseLike(array('enabled' => false))
113+
->treatTrueLike(array('enabled' => true))
114+
->treatNullLike(array('enabled' => true))
115+
->children()
116+
->scalarNode('enabled')->defaultTrue()->end()
117+
->scalarNode('name')->defaultValue('flashes')->end()
118+
->scalarNode('path')->defaultValue('/')->end()
119+
->scalarNode('domain')->defaultNull()->info('depreciated, use host instead')->end()
120+
->scalarNode('host')->defaultNull()->info('URL host name')->end()
121+
->scalarNode('secure')->defaultFalse()->end()
122+
->scalarNode('httpOnly')->defaultTrue()->end()
123+
->end()
124+
->end()
125+
->end();
126+
}
127+
128+
private function addInvalidatorsSection(ArrayNodeDefinition $rootNode)
129+
{
130+
$rootNode
131+
->children()
39132
->arrayNode('invalidators')
40133
->useAttributeAsKey('name')
41134
->prototype('array')
@@ -57,8 +150,7 @@ public function getConfigTreeBuilder()
57150
->end()
58151
->end()
59152
->end()
60-
->end();
61-
62-
return $treeBuilder;
153+
->end()
154+
->end();
63155
}
64156
}

DependencyInjection/DriebitHttpCacheExtension.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

liipDependencyInjection/LiipCacheControlExtension.php renamed to DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
<?php
22

3-
namespace Liip\CacheControlBundle\DependencyInjection;
4-
5-
use Symfony\Component\Config\Definition\Processor,
6-
Symfony\Component\Config\FileLocator,
7-
Symfony\Component\HttpKernel\DependencyInjection\Extension,
8-
Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
9-
Symfony\Component\DependencyInjection\ContainerBuilder,
10-
Symfony\Component\DependencyInjection\Reference,
11-
Symfony\Component\DependencyInjection\DefinitionDecorator,
12-
Symfony\Component\DependencyInjection\Exception\RuntimeException;
13-
14-
class LiipCacheControlExtension extends Extension
3+
namespace FOS\HttpCacheBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\DependencyInjection\DefinitionDecorator;
8+
use Symfony\Component\DependencyInjection\Reference;
9+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10+
use Symfony\Component\DependencyInjection\Loader;
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
class FOSHttpCacheExtension extends Extension
1516
{
1617
/**
17-
* Loads the services based on your application configuration.
18-
*
19-
* @param array $configs
20-
* @param ContainerBuilder $container
18+
* {@inheritDoc}
2119
*/
2220
public function load(array $configs, ContainerBuilder $container)
2321
{
24-
$processor = new Processor();
2522
$configuration = new Configuration();
26-
$config = $processor->processConfiguration($configuration, $configs);
23+
$config = $this->processConfiguration($configuration, $configs);
2724

28-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25+
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.xml');
2927

3028
$container->setParameter($this->getAlias().'.debug', $config['debug']);
29+
$container->setParameter($this->getAlias().'.invalidators', $config['invalidators']);
3130

3231
if (!empty($config['rules'])) {
3332
$loader->load('rule_response_listener.xml');
@@ -61,21 +60,10 @@ public function load(array $configs, ContainerBuilder $container)
6160
}
6261
}
6362

64-
if (!empty($config['varnish'])) {
65-
66-
if (!extension_loaded('curl')) {
67-
throw new RuntimeException('Varnish Helper requires cUrl php extension. Please install it to continue');
68-
69-
}
70-
71-
// domain is depreciated and will be removed in future
72-
$host = is_null($config['varnish']['host']) && $config['varnish']['domain'] ? $config['varnish']['domain'] : $config['varnish']['host'];
73-
74-
$loader->load('varnish_helper.xml');
63+
if (isset($config['varnish'])) {
64+
$loader->load('varnish.xml');
7565
$container->setParameter($this->getAlias().'.varnish.ips', $config['varnish']['ips']);
76-
$container->setParameter($this->getAlias().'.varnish.host', $host);
77-
$container->setParameter($this->getAlias().'.varnish.port', $config['varnish']['port']);
78-
$container->setParameter($this->getAlias().'.varnish.purge_instruction', $config['varnish']['purge_instruction']);
66+
$container->setParameter($this->getAlias().'.varnish.host', $config['varnish']['host']);
7967
}
8068

8169
if ($config['authorization_listener']) {

DriebitHttpCacheBundle.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

EventListener/CacheAuthorizationListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Liip\CacheControlBundle\EventListener;
3+
namespace FOS\HttpCacheBundle\EventListener;
44

55
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
66
use Symfony\Component\HttpFoundation\Response;

EventListener/CacheControlListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Liip\CacheControlBundle\EventListener;
3+
namespace FOS\HttpCacheBundle\EventListener;
44

55
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
66
use Symfony\Component\HttpFoundation\Response;

EventListener/FlashMessageListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Liip\CacheControlBundle\EventListener;
3+
namespace FOS\HttpCacheBundle\EventListener;
44

55
use Symfony\Component\HttpKernel\Event\FilterResponseEvent,
66
Symfony\Component\HttpFoundation\Session,

EventListener/InvalidationListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace Driebit\HttpCacheBundle\EventListener;
3+
namespace FOS\HttpCacheBundle\EventListener;
44

5-
use Driebit\HttpCacheBundle\CacheManager;
6-
use Driebit\HttpCacheBundle\Invalidator\InvalidatorCollection;
5+
use FOS\HttpCacheBundle\CacheManager;
6+
use FOS\HttpCacheBundle\Invalidator\InvalidatorCollection;
77
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
88
use Symfony\Component\HttpKernel\KernelEvents;
99
use Symfony\Component\HttpKernel\Event\PostResponseEvent;

FOSHttpCacheBundle.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace FOS\HttpCacheBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class FOSHttpCacheBundle extends Bundle
8+
{
9+
}

Invalidator/Invalidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Driebit\HttpCacheBundle\Invalidator;
3+
namespace FOS\HttpCacheBundle\Invalidator;
44

55
/**
66
* {@inheritdoc}

Invalidator/InvalidatorCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Driebit\HttpCacheBundle\Invalidator;
3+
namespace FOS\HttpCacheBundle\Invalidator;
44

55
/**
66
* A collection of invalidators

0 commit comments

Comments
 (0)