Skip to content

Commit

Permalink
bug symfony#50793 [DependencyInjection] Fix resource tracking for laz…
Browse files Browse the repository at this point in the history
…y services (nicolas-grekas)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Fix resource tracking for lazy services

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix symfony#50792
| License       | MIT
| Doc PR        | -

Commits
-------

0f737d8 [DependencyInjection] Fix resource tracking for lazy services
  • Loading branch information
nicolas-grekas committed Jun 28, 2023
2 parents 75319a2 + 0f737d8 commit 3fe8e02
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Dumper;

use Composer\Autoload\ClassLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
Expand Down Expand Up @@ -555,8 +556,19 @@ private function generateProxyClasses(): array
continue;
}
$alreadyGenerated[$asGhostObject][$class] = true;
// register class' reflector for resource tracking
$this->container->getReflectionClass($class);

$r = $this->container->getReflectionClass($class);
do {
$file = $r->getFileName();
if (str_ends_with($file, ') : eval()\'d code')) {
$file = substr($file, 0, strrpos($file, '(', -17));
}
if (is_file($file)) {
$this->container->addResource(new FileResource($file));
}
$r = $r->getParentClass() ?: null;
} while ($r?->isUserDefined());

if ("\n" === $proxyCode = "\n".$proxyDumper->getProxyCode($definition, $id)) {
continue;
}
Expand Down

0 comments on commit 3fe8e02

Please sign in to comment.