8000 [DependencyInjection] Optimize PHP preloading · symfony/symfony@e320c71 · GitHub
[go: up one dir, main page]

Skip to content

Commit e320c71

Browse files
committed
[DependencyInjection] Optimize PHP preloading
1 parent 1629b59 commit e320c71

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class %s extends {$options['class']}
342342

343343
$code[$options['class'].'.preload.php'] .= <<<'EOF'
344344
345-
Preloader::preload($classes);
345+
$preloaded = Preloader::preload($classes);
346346

347347
EOF;
348348
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function append(string $file, array $list): void
3737
file_put_contents($file, sprintf("\n\$classes = [];\n%sPreloader::preload(\$classes);\n", implode('', $classes)), \FILE_APPEND);
3838
}
3939

40-
public static function preload(array $classes): void
40+
public static function preload(array $classes, array $preloaded = []): array
4141
{
4242
set_error_handler(function ($t, $m, $f, $l) {
4343
if (error_reporting() & $t) {
@@ -50,7 +50,6 @@ public static function preload(array $classes): void
5050
});
5151

5252
$prev = [];
53-
$preloaded = [];
5453

5554
try {
5655
while ($prev !== $classes) {
@@ -65,6 +64,8 @@ public static function preload(array $classes): void
6564
} finally {
6665
restore_error_handler();
6766
}
67+
68+
return $preloaded;
6869
}
6970

7071
private static function doPreload(string $class, array &$preloaded): void
@@ -76,6 +77,10 @@ private static function doPreload(string $class, array &$preloaded): void
7677
$preloaded[$class] = true;
7778

7879
try {
80+
if (!class_exists($class)) {
81+
return;
82+
}
83+
7984
$r = new \ReflectionClass($class);
8085

8186
if ($r->isInternal()) {

0 commit comments

Comments
 (0)
0