8000 [FrameworkBundle] Fallback to default cache system in production for … · symfony/symfony@7b24391 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b24391

Browse files
committed
[FrameworkBundle] Fallback to default cache system in production for some services
1 parent f1d12a1 commit 7b24391

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ public function load(array $configs, ContainerBuilder $container)
116116
$this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader);
117117
}
118118

119+
$this->registerCacheConfiguration($config['cache'], $container, $loader);
119120
$this->registerValidationConfiguration($config['validation'], $container, $loader);
120121
$this->registerEsiConfiguration($config['esi'], $container, $loader);
121122
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
122123
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
123124
$this->registerTranslatorConfiguration($config['translator'], $container);
124125
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
125-
$this->registerCacheConfiguration($config['cache'], $container, $loader);
126126

127127
if ($this->isConfigEnabled($container, $config['router'])) {
128128
$this->registerRouterConfiguration($config['router'], $container, $loader);
@@ -781,14 +781,16 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
781781
}
782782
}
783783

784-
if (isset($config['cache'])) {
785-
$container->setParameter(
786-
'validator.mapping.cache.prefix',
787-
'validator_'.$this->getKernelRootHash($container)
788-
);
789-
790-
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
784+
if (!isset($config['cache'])) {
785+
$config['cache'] = 'validator.mapping.cache.symfony.static';
791786
}
787+
788+
$container->setParameter(
789+
'validator.mapping.cache.prefix',
790+
'validator_'.$this->getKernelRootHash($container)
791+
);
792+
793+
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
792794
}
793795

794796
private function getValidatorMappingFiles(ContainerBuilder $container)

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<service id="cache.adapter.shared" alias="cache.adapter.filesystem" />
1414
<service id="cache.adapter.local" alias="cache.adapter.filesystem" />
15+
<service id="cache.adapter.static" alias="cache.adapter.filesystem" />
1516

1617
<service id="cache.pool.shared" parent="cache.adapter.shared">
1718
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
@@ -21,6 +22,10 @@
2122
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
2223
</service>
2324

25+
<service id="cache.pool.validator" parent="cache.adapter.static">
26+
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
27+
</service>
28+
2429
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
2530
<argument /> <!-- namespace -->
2631
<argument /> <!-- default lifetime -->

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
<service id="validator.mapping.class_metadata_factory" alias="validator" public="false" />
3030

31+
<service id="validator.mapping.cache.symfony.static" class="Symfony\Component\Validator\Mapping\Cache\Psr6Cache" public="false">
32+
<argument type="service" id="cache.pool.validator" />
33+
</service>
34+
3135
<service id="validator.mapping.cache.doctrine.apc" class="Symfony\Component\Validator\Mapping\Cache\DoctrineCache" public="false">
3236
<argument type="service">
3337
<service class="Doctrine\Common\Cache\ApcCache">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,13 @@ public function testValidationAnnotations()
350350

351351
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
352352

353-
$this->assertCount(6, $calls);
353+
$this->assertCount(7, $calls);
354354
$this->assertSame('enableAnnotationMapping', $calls[4][0]);
355355
$this->assertEquals(array(new Reference('annotation_reader')), $calls[4][1]);
356356
$this->assertSame('addMethodMapping', $calls[5][0]);
357357
$this->assertSame(array('loadValidatorMetadata'), $calls[5][1]);
358+
$this->assertSame('setMetadataCache', $calls[6][0]);
359+
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony.static')), $calls[6][1]);
358360
// no cache this time
359361
}
360362

@@ -368,12 +370,14 @@ public function testValidationPaths()
368370

369371
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
370372

371-
$this->assertCount(7, $calls);
373+
$this->assertCount(8, $calls);
372374
$this->assertSame('addXmlMappings', $calls[3][0]);
373375
$this->assertSame('addYamlMappings', $calls[4][0]);
374376
$this->assertSame('enableAnnotationMapping', $calls[5][0]);
375377
$this->assertSame('addMethodMapping', $calls[6][0]);
376378
$this->assertSame(array('loadValidatorMetadata'), $calls[6][1]);
379+
$this->assertSame('setMetadataCache', $calls[7][0]);
380+
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony.static')), $calls[7][1]);
377381

378382
$xmlMappings = $calls[3][1][0];
379383
$this->assertCount(2, $xmlMappings);
@@ -397,8 +401,10 @@ public function testValidationNoStaticMethod()
397401

398402
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
399403

400-
$this->assertCount(4, $calls);
404+
$this->assertCount(5, $calls);
401405
$this->assertSame('addXmlMappings', $calls[3][0]);
406+
$this->assertSame('setMetadataCache', $calls[4][0]);
407+
$this->assertEquals(array(new Reference('validator.mapping.cache.symfony.static')), $calls[4][1]);
402408
// no cache, no annotations, no static methods
403409
}
404410

0 commit comments

Comments
 (0)
0