Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 015c3d0

Browse filesBrowse files
committed
[FrameworkBundle] Fallback to default cache system in production for some services
1 parent f1d12a1 commit 015c3d0
Copy full SHA for 015c3d0

File tree

Expand file treeCollapse file tree

6 files changed

+33
-18
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+33
-18
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class CachePoolPass implements CompilerPassInterface
2626
*/
2727
public function process(ContainerBuilder $container)
2828
{
29+
$namespaceSuffix = '.'.$container->getParameter('kernel.container_class');
30+
$namespaceSuffix .= '.'.$container->getParameter('kernel.root_dir');
31+
2932
$attributes = array(
3033
'provider',
3134
'namespace',
@@ -36,9 +39,7 @@ public function process(ContainerBuilder $container)
3639
if ($pool->isAbstract()) {
3740
continue;
3841
}
39-
if (!isset($tags[0]['namespace'])) {
40-
$tags[0]['namespace'] = $this->getNamespace($id);
41-
}
42+
$tags[0]['namespace'] = $this->getNamespace($namespaceSuffix, isset($tags[0]['namespace']) ? $tags[0]['namespace'] : $id);
4243
while ($adapter instanceof DefinitionDecorator) {
4344
$adapter = $container->findDefinition($adapter->getParent());
4445
if ($t = $adapter->getTag('cache.pool')) {
@@ -72,8 +73,8 @@ public function process(ContainerBuilder $container)
7273
}
7374
}
7475

75-
private function getNamespace($id)
76+
private function getNamespace($namespaceSuffix, $id)
7677
{
77-
return substr(str_replace('/', '-', base64_encode(md5('symfony.'.$id, true))), 0, 10);
78+
return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10);
7879
}
7980
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
468468
->info('validation configuration')
469469
->canBeEnabled()
470470
->children()
471-
->scalarNode('cache')->end()
471+
->scalarNode('cache')->defaultValue('validator.mapping.cache.symfony')->end()
472472
->booleanNode('enable_annotations')->defaultFalse()->end()
473473
->arrayNode('static_method')
474474
->defaultValue(array('loadValidatorMetadata'))

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function load(array $configs, ContainerBuilder $container)
7171
// Property access is used by both the Form and the Validator component
7272
$loader->load('property_access.xml');
7373

74+
// Load Cache configuration first as it is used by other components
75+
$loader->load('cache_pools.xml');
76+
7477
$configuration = $this->getConfiguration($configs, $container);
7578
$config = $this->processConfiguration($configuration, $configs);
7679

@@ -781,14 +784,12 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
781784
}
782785
}
783786

784-
if (isset($config['cache'])) {
785-
$container->setParameter(
786-
'validator.mapping.cache.prefix',
787-
'validator_'.$this->getKernelRootHash($container)
788-
);
787+
$container->setParameter(
788+
'validator.mapping.cache.prefix',
789+
'validator_'.$this->getKernelRootHash($container)
790+
);
789791

790-
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
791-
}
792+
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
792793
}
793794

794795
private function getValidatorMappingFiles(ContainerBuilder $container)
@@ -1019,8 +1020,6 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
10191020

10201021
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
10211022
{
1022-
$loader->load('cache_pools.xml');
1023-
10241023
foreach ($config['pools'] as $name => $poolConfig) {
10251024
$poolDefinition = new DefinitionDecorator($poolConfig['adapter']);
10261025
$poolDefinition->setPublic($poolConfig['public']);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml
+4Lines 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" 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+9-3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.