Skip to content

Commit

Permalink
minor #16941 [FrameworkBundle] Compute the kernel root hash only one …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Jan 25, 2016
2 parents e68ebab + 23431e9 commit c738085
Showing 1 changed file with 23 additions and 2 deletions.
Expand Up @@ -38,6 +38,11 @@ class FrameworkExtension extends Extension
private $translationConfigEnabled = false;
private $sessionConfigEnabled = false;

/**
* @var string|null
*/
private $kernelRootHash;

/**
* Responds to the app.config configuration parameter.
*
Expand Down Expand Up @@ -779,7 +784,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
if (isset($config['cache'])) {
$container->setParameter(
'validator.mapping.cache.prefix',
'validator_'.hash('sha256', $container->getParameter('kernel.root_dir'))
'validator_'.$this->getKernelRootHash($container)
);

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

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

/**
* 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.
*
Expand Down

0 comments on commit c738085

Please sign in to comment.