Skip to content

Merge bundles #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ language: php
php:
- 5.3
- 5.4
- 5.5

env:
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.4.*
- SYMFONY_VERSION=dev-master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symfony 2.4 is out, so that should be in this list too.

do we still care about symfony < 2.3? i would suggest to ditch those, they are EOL and people still on symfony 2.1/2.2 can use the old LiipCacheControlBundle which will remain available for legacy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


before_script:
- composer install --dev
- composer require symfony/framework-bundle:${SYMFONY_VERSION}

script: phpunit --coverage-text
21 changes: 17 additions & 4 deletions CacheManager.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Driebit\HttpCacheBundle;
namespace FOS\HttpCacheBundle;

use Driebit\HttpCacheBundle\HttpCache\HttpCacheInterface;
use FOS\HttpCacheBundle\HttpCache\HttpCacheInterface;
use Symfony\Component\Routing\RouterInterface;

/**
Expand Down Expand Up @@ -47,9 +47,9 @@ public function __construct(HttpCacheInterface $cache, RouterInterface $router)
*
* @return $this
*/
public function invalidatePath($path)
public function invalidatePath($path, array $headers = array())
{
$this->invalidationQueue[$path] = $path;
$this->invalidationQueue[$path] = $headers;

return $this;
}
Expand All @@ -69,6 +69,19 @@ public function invalidateRoute($name, $parameters = array())
return $this;
}

public function refreshPath($path, $headers)
{
$headers = array("Cache-Control: no-cache, no-store, max-age=0, must-revalidate");

}



public function invalidateRegex($regex)
{

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks incomplete. can you create an issue and a TODO with a link to the issue so we can keep track of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18


/**
* Flush all paths queued for invalidation
*
Expand Down
122 changes: 107 additions & 15 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Driebit\HttpCacheBundle\DependencyInjection;
namespace FOS\HttpCacheBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -18,24 +19,116 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('driebit_http_cache');
$rootNode = $treeBuilder->root('fos_http_cache');

$rootNode
->children()
->arrayNode('http_cache')->isRequired()
->children()
->arrayNode('varnish')
->children()
->scalarNode('host')->isRequired()->end()
->arrayNode('ips')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
->booleanNode('authorization_listener')->defaultFalse()->end()
->end()
;

$this->addRulesSection($rootNode);
$this->addVarnishSection($rootNode);
$this->addFlashMessageListenerSection($rootNode);
$this->addInvalidatorsSection($rootNode);

return $treeBuilder;
}

private function addRulesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->fixXmlConfig('rule', 'rules')
->children()
->arrayNode('rules')
->cannotBeOverwritten()
->prototype('array')
->children()
->scalarNode('unless_role')->defaultNull()->end()
->scalarNode('path')->defaultNull()->info('URL path info')->end()
->arrayNode('method')
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->info('HTTP method')
->end()
->arrayNode('ips')
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->info('List of ips')
->end()
->arrayNode('attributes')
->addDefaultsIfNotSet()
->cannotBeEmpty()
->treatNullLike(array())
->info('Request attributes')
->end()
->scalarNode('domain')->defaultNull()->info('depreciated, use host instead')->end()
->scalarNode('host')->defaultNull()->info('URL host name')->end()
->scalarNode('controller')->defaultNull()->info('controller action name')->end()
->scalarNode('reverse_proxy_ttl')->defaultNull()->end()
->arrayNode('controls')
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->arrayNode('vary')
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end();
}

private function addVarnishSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('varnish')
->children()
->arrayNode('ips')
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
->useAttributeAsKey('name')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->scalarNode('host')->defaultNull()->info('Default host name')->end()
->end()
->end()
->end();
}

private function addFlashMessageListenerSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('flash_message_listener')
->canBeUnset()
->treatFalseLike(array('enabled' => false))
->treatTrueLike(array('enabled' => true))
->treatNullLike(array('enabled' => true))
->children()
->scalarNode('enabled')->defaultTrue()->end()
->scalarNode('name')->defaultValue('flashes')->end()
->scalarNode('path')->defaultValue('/')->end()
->scalarNode('domain')->defaultNull()->info('depreciated, use host instead')->end()
->scalarNode('host')->defaultNull()->info('URL host name')->end()
->scalarNode('secure')->defaultFalse()->end()
->scalarNode('httpOnly')->defaultTrue()->end()
->end()
->end()
->end();
}

private function addInvalidatorsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('invalidators')
->useAttributeAsKey('name')
->prototype('array')
Expand All @@ -57,8 +150,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->end();

return $treeBuilder;
->end()
->end();
}
}
36 changes: 0 additions & 36 deletions DependencyInjection/DriebitHttpCacheExtension.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<?php

namespace Liip\CacheControlBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor,
Symfony\Component\Config\FileLocator,
Symfony\Component\HttpKernel\DependencyInjection\Extension,
Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Reference,
Symfony\Component\DependencyInjection\DefinitionDecorator,
Symfony\Component\DependencyInjection\Exception\RuntimeException;

class LiipCacheControlExtension extends Extension
namespace FOS\HttpCacheBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* {@inheritdoc}
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just have {@inheritDoc} instead of this template phpdoc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

class FOSHttpCacheExtension extends Extension
{
/**
* Loads the services based on your application configuration.
*
* @param array $configs
* @param ContainerBuilder $container
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$config = $this->processConfiguration($configuration, $configs);

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

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

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

if (!empty($config['varnish'])) {

if (!extension_loaded('curl')) {
throw new RuntimeException('Varnish Helper requires cUrl php extension. Please install it to continue');

}

// domain is depreciated and will be removed in future
$host = is_null($config['varnish']['host']) && $config['varnish']['domain'] ? $config['varnish']['domain'] : $config['varnish']['host'];

$loader->load('varnish_helper.xml');
if (isset($config['varnish'])) {
$loader->load('varnish.xml');
$container->setParameter($this->getAlias().'.varnish.ips', $config['varnish']['ips']);
$container->setParameter($this->getAlias().'.varnish.host', $host);
$container->setParameter($this->getAlias().'.varnish.port', $config['varnish']['port']);
$container->setParameter($this->getAlias().'.varnish.purge_instruction', $config['varnish']['purge_instruction']);
$container->setParameter($this->getAlias().'.varnish.host', $config['varnish']['host']);
}

if ($config['authorization_listener']) {
Expand Down
9 changes: 0 additions & 9 deletions DriebitHttpCacheBundle.php

This file was deleted.

2 changes: 1 addition & 1 deletion EventListener/CacheAuthorizationListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\CacheControlBundle\EventListener;
namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Response;
Expand Down
2 changes: 1 addition & 1 deletion EventListener/CacheControlListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\CacheControlBundle\EventListener;
namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
Expand Down
2 changes: 1 addition & 1 deletion EventListener/FlashMessageListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Liip\CacheControlBundle\EventListener;
namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterResponseEvent,
Symfony\Component\HttpFoundation\Session,
Expand Down
6 changes: 3 additions & 3 deletions EventListener/InvalidationListener.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Driebit\HttpCacheBundle\EventListener;
namespace FOS\HttpCacheBundle\EventListener;

use Driebit\HttpCacheBundle\CacheManager;
use Driebit\HttpCacheBundle\Invalidator\InvalidatorCollection;
use FOS\HttpCacheBundle\CacheManager;
use FOS\HttpCacheBundle\Invalidator\InvalidatorCollection;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
Expand Down
9 changes: 9 additions & 0 deletions FOSHttpCacheBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace FOS\HttpCacheBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class FOSHttpCacheBundle extends Bundle
{
}
2 changes: 1 addition & 1 deletion Invalidator/Invalidator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Driebit\HttpCacheBundle\Invalidator;
namespace FOS\HttpCacheBundle\Invalidator;

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion Invalidator/InvalidatorCollection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Driebit\HttpCacheBundle\Invalidator;
namespace FOS\HttpCacheBundle\Invalidator;

/**
* A collection of invalidators
Expand Down
Loading