Skip to content

Always load request_matcher and rule_matcher services #194

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
Feb 20, 2015
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
1 change: 1 addition & 0 deletions DependencyInjection/FOSHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('matcher.xml');
Copy link
Member Author

Choose a reason for hiding this comment

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

I now simply always load matcher.xml, which means rule_matcher and request_matcher will be loaded even if they are not used. I don’t find this a big problem. We could make their loading optional, for instance in the createRule|RequestMatcher() methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

the services being private, they will be removed when the container is built, so this should have 0 runtime impact


if ($config['debug']['enabled'] || (!empty($config['cache_control']))) {
$debugHeader = $config['debug']['enabled'] ? $config['debug']['header'] : false;
Expand Down
15 changes: 0 additions & 15 deletions Resources/config/cache_control_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

<parameters>
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlSubscriber</parameter>
<parameter key="fos_http_cache.request_matcher.class">Symfony\Component\HttpFoundation\RequestMatcher</parameter>
<parameter key="fos_http_cache.rule_matcher.class">FOS\HttpCacheBundle\Http\RuleMatcher</parameter>
</parameters>

<services>
Expand All @@ -16,18 +14,5 @@
<argument>%fos_http_cache.debug_header%</argument>
<tag name="kernel.event_subscriber" />
</service>

<service id="fos_http_cache.request_matcher"
class="%fos_http_cache.request_matcher.class%"
public="false"
/>

<service id="fos_http_cache.rule_matcher"
class="%fos_http_cache.rule_matcher.class%"
public="false"
>
<argument/>
<argument/>
</service>
</services>
</container>
26 changes: 26 additions & 0 deletions Resources/config/matcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="fos_http_cache.request_matcher.class">Symfony\Component\HttpFoundation\RequestMatcher</parameter>
<parameter key="fos_http_cache.rule_matcher.class">FOS\HttpCacheBundle\Http\RuleMatcher</parameter>
</parameters>

<services>
<service id="fos_http_cache.request_matcher"
class="%fos_http_cache.request_matcher.class%"
public="false"
/>

<service id="fos_http_cache.rule_matcher"
class="%fos_http_cache.rule_matcher.class%"
public="false"
>
<argument/>
<argument/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testConfigNoContext()
$config = $this->getBaseConfig();
$this->extension->load(array($config), $container);
$this->userContextListenerPass->process($container);
$this->assertCount(10, $container->getDefinitions());
$this->assertCount(12, $container->getDefinitions());
}

/**
Expand Down
18 changes: 15 additions & 3 deletions Tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

Expand Down Expand Up @@ -149,6 +150,9 @@ public function testConfigLoadInvalidatorRules()

$this->assertMatcherCreated($container, array('_route' => 'my_route'));
$this->assertListenerHasRule($container, 'fos_http_cache.event_listener.invalidation');

// Test for runtime errors
$container->compile();
}

public function testConfigLoadCacheControl()
Expand Down Expand Up @@ -282,9 +286,17 @@ public function testConfigLoadFlashMessageSubscriber()

protected function createContainer()
{
return new ContainerBuilder(new ParameterBag(array(
'kernel.debug' => false,
)));
$container = new ContainerBuilder(
new ParameterBag(array('kernel.debug' => false,))
);

// The cache_manager service depends on the router service
$container->setDefinition(
'router',
new Definition('\Symfony\Component\Routing\Router')
);

return $container;
}

protected function getBaseConfig()
Expand Down