Skip to content

Commit

Permalink
bug #33525 [DI] fix Preloader (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

[DI] fix Preloader

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/32032/files#r322150801
| License       | MIT
| Doc PR        | -

Commits
-------

4cc8641 [DI] fix Preloader
  • Loading branch information
fabpot committed Sep 10, 2019
2 parents 3f0cf49 + 4cc8641 commit 1c3d409
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Symfony/Component/DependencyInjection/Dumper/Preloader.php
Expand Up @@ -38,8 +38,7 @@ public static function preload(array $classes)
$prev = $classes;
foreach ($classes as $c) {
if (!isset($preloaded[$c])) {
$preloaded[$c] = true;
self::doPreload($c);
self::doPreload($c, $preloaded);
}
}
$classes = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
Expand All @@ -49,12 +48,14 @@ public static function preload(array $classes)
}
}

private static function doPreload(string $class)
private static function doPreload(string $class, array &$preloaded)
{
if (\in_array($class, ['self', 'static', 'parent'], true)) {
if (isset($preloaded[$class]) || \in_array($class, ['self', 'static', 'parent'], true)) {
return;
}

$preloaded[$class] = true;

try {
$r = new \ReflectionClass($class);

Expand All @@ -68,7 +69,7 @@ private static function doPreload(string $class)
if (\PHP_VERSION_ID >= 70400) {
foreach ($r->getProperties() as $p) {
if (($t = $p->getType()) && !$t->isBuiltin()) {
self::doPreload($t->getName());
self::doPreload($t->getName(), $preloaded);
}
}
}
Expand All @@ -79,17 +80,17 @@ private static function doPreload(string $class)
$c = $p->getDefaultValueConstantName();

if ($i = strpos($c, '::')) {
self::doPreload(substr($c, 0, $i));
self::doPreload(substr($c, 0, $i), $preloaded);
}
}

if (($t = $p->getType()) && !$t->isBuiltin()) {
self::doPreload($t->getName());
self::doPreload($t->getName(), $preloaded);
}
}

if (($t = $m->getReturnType()) && !$t->isBuiltin()) {
self::doPreload($t->getName());
self::doPreload($t->getName(), $preloaded);
}
}
} catch (\ReflectionException $e) {
Expand Down

0 comments on commit 1c3d409

Please sign in to comment.