[FrameworkBundle] Compute the kernel root hash only one time

This commit is contained in:
Kévin Dunglas 2015-12-10 11:46:31 +01:00
parent 447ea791be
commit 23431e99d6

View File

@ -38,6 +38,11 @@ class FrameworkExtension extends Extension
private $translationConfigEnabled = false; private $translationConfigEnabled = false;
private $sessionConfigEnabled = false; private $sessionConfigEnabled = false;
/**
* @var string|null
*/
private $kernelRootHash;
/** /**
* Responds to the app.config configuration parameter. * Responds to the app.config configuration parameter.
* *
@ -777,7 +782,7 @@ class FrameworkExtension extends Extension
if (isset($config['cache'])) { if (isset($config['cache'])) {
$container->setParameter( $container->setParameter(
'validator.mapping.cache.prefix', 'validator.mapping.cache.prefix',
'validator_'.hash('sha256', $container->getParameter('kernel.root_dir')) 'validator_'.$this->getKernelRootHash($container)
); );
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache']))); $validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
@ -959,7 +964,7 @@ class FrameworkExtension extends Extension
if (isset($config['cache']) && $config['cache']) { if (isset($config['cache']) && $config['cache']) {
$container->setParameter( $container->setParameter(
'serializer.mapping.cache.prefix', 'serializer.mapping.cache.prefix',
'serializer_'.hash('sha256', $container->getParameter('kernel.root_dir')) 'serializer_'.$this->getKernelRootHash($container)
); );
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument( $container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
@ -968,6 +973,22 @@ class FrameworkExtension extends Extension
} }
} }
/**
* Gets a hash of the kernel root directory.
*
* @param ContainerBuilder $container
*
* @return string
*/
private function getKernelRootHash(ContainerBuilder $container)
{
if (!$this->kernelRootHash) {
$this->kernelRootHash = hash('sha256', $container->getParameter('kernel.root_dir'));
}
return $this->kernelRootHash;
}
/** /**
* Returns the base path for the XSD files. * Returns the base path for the XSD files.
* *