Skip to content

Commit 8355d14

Browse files
committed
[FrameworkBundle] Compute the kernel root hash only one time
1 parent bad346d commit 8355d14

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class FrameworkExtension extends Extension
3838
private $translationConfigEnabled = false;
3939
private $sessionConfigEnabled = false;
4040

41+
/**
42+
* @var string|null
43+
*/
44+
private $kernelRootHash;
45+
4146
/**
4247
* Responds to the app.config configuration parameter.
4348
*
@@ -777,7 +782,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
777782
if (isset($config['cache'])) {
778783
$container->setParameter(
779784
'validator.mapping.cache.prefix',
780-
'validator_'.hash('sha256', $container->getParameter('kernel.root_dir'))
785+
'validator_'.$this->getKernelRootHash($container)
781786
);
782787

783788
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
@@ -959,7 +964,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
959964
if (isset($config['cache']) && $config['cache']) {
960965
$container->setParameter(
961966
'serializer.mapping.cache.prefix',
962-
'serializer_'.hash('sha256', $container->getParameter('kernel.root_dir'))
967+
'serializer_'.$this->getKernelRootHash($container)
963968
);
964969

965970
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
@@ -968,6 +973,22 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
968973
}
969974
}
970975

976+
/**
977+
* Gets a hash of the kernel root directory.
978+
*
979+
* @param ContainerBuilder $container
980+
*
981+
* @return string
982+
*/
983+
private function getKernelRootHash(ContainerBuilder $container)
984+
{
985+
if (!$this->kernelRootHash) {
986+
$this->kernelRootHash = hash('sha256', $container->getParameter('kernel.root_dir'));
987+
}
988+
989+
return $this->kernelRootHash;
990+
}
991+
971992
/**
972993
* Returns the base path for the XSD files.
973994
*

0 commit comments

Comments
 (0)