Skip to content

Commit 3fe8e02

Browse files
bug symfony#50793 [DependencyInjection] Fix resource tracking for lazy 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
2 parents 75319a2 + 0f737d8 commit 3fe8e02

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Dumper;
1313

1414
use Composer\Autoload\ClassLoader;
15+
use Symfony\Component\Config\Resource\FileResource;
1516
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1617
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1718
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
@@ -555,8 +556,19 @@ private function generateProxyClasses(): array
555556
continue;
556557
}
557558
$alreadyGenerated[$asGhostObject][$class] = true;
558-
// register class' reflector for resource tracking
559-
$this->container->getReflectionClass($class);
559+
560+
$r = $this->container->getReflectionClass($class);
561+
do {
562+
$file = $r->getFileName();
563+
if (str_ends_with($file, ') : eval()\'d code')) {
564+
$file = substr($file, 0, strrpos($file, '(', -17));
565+
}
566+
if (is_file($file)) {
567+
$this->container->addResource(new FileResource($file));
568+
}
569+
$r = $r->getParentClass() ?: null;
570+
} while ($r?->isUserDefined());
571+
560572
if ("\n" === $proxyCode = "\n".$proxyDumper->getProxyCode($definition, $id)) {
561573
continue;
562574
}

0 commit comments

Comments
 (0)