Skip to content

Commit e3739b1

Browse files
committed
[Bridge\ProxyManager] isProxyCandidate() does not take into account interfaces
When using factories it's common best practice to use interface as class name, especially in cases where you know impl can differ. Before this fix ProxyManager did not allow these to be lazy. In our case this has lead several to hard to debug issues on classes we need to mark as lazyi and often a need to add lazy on decorators if there are any or other workarounds. As we have had this issue, and still have on both 2.8 and 3.4 this is opened against 2.8.
1 parent 365a390 commit e3739b1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct($salt = '')
4747
*/
4848
public function isProxyCandidate(Definition $definition)
4949
{
50-
return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
50+
return $definition->isLazy() && ($class = $definition->getClass()) && (class_exists($class) || interface_exists($class));
5151
}
5252

5353
/**

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
18+
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
1819

1920
/**
2021
* Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper}.
@@ -137,6 +138,7 @@ public function getProxyCandidates()
137138
$definitions = [
138139
[new Definition(__CLASS__), true],
139140
[new Definition('stdClass'), true],
141+
[new Definition(DumperInterface::class), true],
140142
[new Definition(uniqid('foo', true)), false],
141143
[new Definition(), false],
142144
];

0 commit comments

Comments
 (0)