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

Skip to content

Commit 41c6b48

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

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function load(array $configs, ContainerBuilder $container)
6868
// will be used and everything will still work as expected.
6969
$loader->load('translation.xml');
7070

71+
// Cache component is used by the Validator component and will be used
72+
// by others in the future
73+
$loader->load('cache_pools.xml');
74+
7175
// Property access is used by both the Form and the Validator component
7276
$loader->load('property_access.xml');
7377

@@ -781,14 +785,16 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
781785
}
782786
}
783787

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'])));
788+
if (!isset($config['cache'])) {
789+
$config['cache'] = 'validator.mapping.cache.symfony.static';
791790
}
791+
792+
$container->setParameter(
793+
'validator.mapping.cache.prefix',
794+
'validator_'.$this->getKernelRootHash($container)
795+
);
796+
797+
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
792798
}
793799

794800
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