diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index 9598f537a0c6..4b8e0afb7bb3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -26,6 +26,14 @@ class CachePoolPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { + $namespaceSuffix = ''; + + foreach (array('name', 'root_dir', 'environment', 'debug') as $key) { + if ($container->hasParameter('kernel.'.$key)) { + $namespaceSuffix .= '.'.$container->getParameter('kernel.'.$key); + } + } + $attributes = array( 'provider', 'namespace', @@ -36,9 +44,7 @@ public function process(ContainerBuilder $container) if ($pool->isAbstract()) { continue; } - if (!isset($tags[0]['namespace'])) { - $tags[0]['namespace'] = $this->getNamespace($id); - } + $tags[0]['namespace'] = $this->getNamespace($namespaceSuffix, isset($tags[0]['namespace']) ? $tags[0]['namespace'] : $id); while ($adapter instanceof DefinitionDecorator) { $adapter = $container->findDefinition($adapter->getParent()); if ($t = $adapter->getTag('cache.pool')) { @@ -72,8 +78,8 @@ public function process(ContainerBuilder $container) } } - private function getNamespace($id) + private function getNamespace($namespaceSuffix, $id) { - return substr(str_replace('/', '-', base64_encode(md5('symfony.'.$id, true))), 0, 10); + return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index e298b2609ce4..7d8bf5f0a03e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -468,7 +468,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode) ->info('validation configuration') ->canBeEnabled() ->children() - ->scalarNode('cache')->end() + ->scalarNode('cache')->defaultValue('validator.mapping.cache.symfony')->end() ->booleanNode('enable_annotations')->defaultFalse()->end() ->arrayNode('static_method') ->defaultValue(array('loadValidatorMetadata')) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 014f447ba103..16e8fce46335 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -71,6 +71,9 @@ public function load(array $configs, ContainerBuilder $container) // Property access is used by both the Form and the Validator component $loader->load('property_access.xml'); + // Load Cache configuration first as it is used by other components + $loader->load('cache_pools.xml'); + $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); @@ -781,7 +784,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder } } - if (isset($config['cache'])) { + if (!$container->getParameter('kernel.debug')) { $container->setParameter( 'validator.mapping.cache.prefix', 'validator_'.$this->getKernelRootHash($container) @@ -1019,8 +1022,6 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { - $loader->load('cache_pools.xml'); - foreach ($config['pools'] as $name => $poolConfig) { $poolDefinition = new DefinitionDecorator($poolConfig['adapter']); $poolDefinition->setPublic($poolConfig['public']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml index 2874f41bf9d2..7a567896a0dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml @@ -21,6 +21,10 @@ + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml index ce317f35e1ab..aa35244a5d89 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml @@ -28,6 +28,10 @@ + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php index 3fc66cff0908..1f77cdd0fe60 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php @@ -41,7 +41,7 @@ public function testNamespaceArgumentIsReplaced() $this->cachePoolPass->process($container); - $this->assertSame('yRnzIIVLvL', $cachePool->getArgument(0)); + $this->assertSame('VcRIZlUhEv', $cachePool->getArgument(0)); } public function testArgsAreReplaced() @@ -61,7 +61,7 @@ public function testArgsAreReplaced() $this->assertInstanceOf(Reference::class, $cachePool->getArgument(0)); $this->assertSame('foobar', (string) $cachePool->getArgument(0)); - $this->assertSame('yRnzIIVLvL', $cachePool->getArgument(1)); + $this->assertSame('VcRIZlUhEv', $cachePool->getArgument(1)); $this->assertSame(3, $cachePool->getArgument(2)); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 9bcadc68102c..b41d568c64fb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -211,6 +211,7 @@ protected static function getBundleDefaultConfig() 'static_method' => array('loadValidatorMetadata'), 'translation_domain' => 'validators', 'strict_email' => false, + 'cache' => 'validator.mapping.cache.symfony', ), 'annotations' => array( 'cache' => 'file', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 000ec8e6ff38..6fdcb3e08d57 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -323,7 +323,7 @@ public function testValidation() public function testValidationService() { - $container = $this->createContainerFromFile('validation_annotations'); + $container = $this->createContainerFromFile('validation_annotations', array('kernel.charset' => 'UTF-8'), false); $this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator')); } @@ -350,11 +350,13 @@ public function testValidationAnnotations() $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - $this->assertCount(6, $calls); + $this->assertCount(7, $calls); $this->assertSame('enableAnnotationMapping', $calls[4][0]); $this->assertEquals(array(new Reference('annotation_reader')), $calls[4][1]); $this->assertSame('addMethodMapping', $calls[5][0]); $this->assertSame(array('loadValidatorMetadata'), $calls[5][1]); + $this->assertSame('setMetadataCache', $calls[6][0]); + $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[6][1]); // no cache this time } @@ -368,12 +370,14 @@ public function testValidationPaths() $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - $this->assertCount(7, $calls); + $this->assertCount(8, $calls); $this->assertSame('addXmlMappings', $calls[3][0]); $this->assertSame('addYamlMappings', $calls[4][0]); $this->assertSame('enableAnnotationMapping', $calls[5][0]); $this->assertSame('addMethodMapping', $calls[6][0]); $this->assertSame(array('loadValidatorMetadata'), $calls[6][1]); + $this->assertSame('setMetadataCache', $calls[7][0]); + $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[7][1]); $xmlMappings = $calls[3][1][0]; $this->assertCount(2, $xmlMappings); @@ -397,8 +401,10 @@ public function testValidationNoStaticMethod() $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - $this->assertCount(4, $calls); + $this->assertCount(5, $calls); $this->assertSame('addXmlMappings', $calls[3][0]); + $this->assertSame('setMetadataCache', $calls[4][0]); + $this->assertEquals(array(new Reference('validator.mapping.cache.symfony')), $calls[4][1]); // no cache, no annotations, no static methods } @@ -594,7 +600,7 @@ protected function createContainer(array $data = array()) ), $data))); } - protected function createContainerFromFile($file, $data = array()) + protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true) { $cacheKey = md5(get_class($this).$file.serialize($data)); if (isset(self::$containerCache[$cacheKey])) { @@ -604,8 +610,10 @@ protected function createContainerFromFile($file, $data = array()) $container->registerExtension(new FrameworkExtension()); $this->loadFromFile($container, $file); - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); + if ($resetCompilerPasses) { + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + } $container->compile(); return self::$containerCache[$cacheKey] = $container; diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 8016bc3ea47c..2570b6c40bb4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -48,7 +48,7 @@ "symfony/expression-language": "~2.8|~3.0", "symfony/process": "~2.8|~3.0", "symfony/serializer": "~2.8|^3.0", - "symfony/validator": "~2.8|~3.0", + "symfony/validator": "~3.1", "symfony/yaml": "~2.8|~3.0", "symfony/property-info": "~2.8|~3.0", "phpdocumentor/reflection-docblock": "^3.0",