Skip to content

Commit c9ba418

Browse files
committed
minor #16941 [FrameworkBundle] Compute the kernel root hash only one time (dunglas)
This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] Compute the kernel root hash only one time | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 23431e9 [FrameworkBundle] Compute the kernel root hash only one time
2 parents 9c71615 + 8355d14 commit c9ba418

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
*
@@ -779,7 +784,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
779784
if (isset($config['cache'])) {
780785
$container->setParameter(
781786
'validator.mapping.cache.prefix',
782-
'validator_'.hash('sha256', $container->getParameter('kernel.root_dir'))
787+
'validator_'.$this->getKernelRootHash($container)
783788
);
784789

785790
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
@@ -961,7 +966,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
961966
if (isset($config['cache']) && $config['cache']) {
962967
$container->setParameter(
963968
'serializer.mapping.cache.prefix',
964-
'serializer_'.hash('sha256', $container->getParameter('kernel.root_dir'))
969+
'serializer_'.$this->getKernelRootHash($container)
965970
);
966971

967972
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
@@ -970,6 +975,22 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
970975
}
971976
}
972977

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

0 commit comments

Comments
 (0)