Skip to content

Commit b77d8c5

Browse files
committed
bug symfony#14501 [ProxyBridge] Fix proxy classnames generation (xphere)
This PR was merged into the 2.3 branch. Discussion ---------- [ProxyBridge] Fix proxy classnames generation | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A When having many lazy services based on the same class, proxy classnames collision is more prone to happen on cache regeneration. The problem comes from [`ProxyDumper`](https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php#L112) usage of [`spl_object_hash`](http://php.net/manual/en/function.spl-object-hash.php), because object hashes may be reused for others when destroyed. To solve this, I added more entropy with an optional salt to allow multiple passes of the `ProxyDumper`, each time with a value coming from the filepath of the cache we're building, so no collision could happen. This applies from `symfony/2.3` to `symfony/2.7`. Related tests are passing. Commits ------- afc39ee add more entropy to generated classnames
2 parents b6de1f3 + afc39ee commit b77d8c5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
*/
2727
class ProxyDumper implements DumperInterface
2828
{
29+
/**
30+
* @var string
31+
*/
32+
private $salt;
33+
2934
/**
3035
* @var LazyLoadingValueHolderGenerator
3136
*/
@@ -38,9 +43,12 @@ class ProxyDumper implements DumperInterface
3843

3944
/**
4045
* Constructor.
46+
*
47+
* @param string $salt
4148
*/
42-
public function __construct()
49+
public function __construct($salt = '')
4350
{
51+
$this->salt = $salt;
4452
$this->proxyGenerator = new LazyLoadingValueHolderGenerator();
4553
$this->classGenerator = new BaseGeneratorStrategy();
4654
}
@@ -109,6 +117,6 @@ public function getProxyCode(Definition $definition)
109117
*/
110118
private function getProxyClassName(Definition $definition)
111119
{
112-
return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition);
120+
return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition).$this->salt;
113121
}
114122
}

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function getBundle($name, $first = true)
243243
}
244244

245245
/**
246-
* {@inheritDoc}
246+
* {@inheritdoc}
247247
*
248248
* @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
249249
*/
@@ -683,7 +683,7 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
683683
$dumper = new PhpDumper($container);
684684

685685
if (class_exists('ProxyManager\Configuration')) {
686-
$dumper->setProxyDumper(new ProxyDumper());
686+
$dumper->setProxyDumper(new ProxyDumper(md5((string) $cache)));
687687
}
688688

689689
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => (string) $cache));

0 commit comments

Comments
 (0)