Skip to content

Commit

Permalink
bug #31551 [ProxyManager] isProxyCandidate() does not take into accou…
Browse files Browse the repository at this point in the history
…nt interfaces (andrerom)

This PR was merged into the 3.4 branch.

Discussion
----------

[ProxyManager] isProxyCandidate() does not take into account interfaces

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        | N/A

When using factories it's common best practice to use interface as class name, especially in cases
where you know implementation can differ. Before this fix ProxyManager did not allow these to be lazy.

As we have have this issue on 2.8 and 3.4. it's very hard to debug, and goes against best practice for factories to not fix it, this is suggested for 2.8.

Commits
-------

e3739b1 [Bridge\ProxyManager] isProxyCandidate() does not take into account interfaces
  • Loading branch information
nicolas-grekas committed May 20, 2019
2 parents 365a390 + e3739b1 commit e24e7dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Expand Up @@ -47,7 +47,7 @@ public function __construct($salt = '')
*/
public function isProxyCandidate(Definition $definition)
{
return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
return $definition->isLazy() && ($class = $definition->getClass()) && (class_exists($class) || interface_exists($class));
}

/**
Expand Down
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;

/**
* Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper}.
Expand Down Expand Up @@ -137,6 +138,7 @@ public function getProxyCandidates()
$definitions = [
[new Definition(__CLASS__), true],
[new Definition('stdClass'), true],
[new Definition(DumperInterface::class), true],
[new Definition(uniqid('foo', true)), false],
[new Definition(), false],
];
Expand Down

0 comments on commit e24e7dc

Please sign in to comment.