Skip to content

Commit a7b5080

Browse files
bug symfony#20725 [HttpKernel] Fix annotation cache warmer with failing or missing classes (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [HttpKernel] Fix annotation cache warmer with failing or missing classes | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#20720 | License | MIT | Doc PR | - Commits ------- dcf9fbb [HttpKernel] Fix annotation cache warmer with failing or missing classes
2 parents 2293b18 + dcf9fbb commit a7b5080

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ public function warmUp($cacheDir)
6666

6767
$arrayPool = new ArrayAdapter(0, false);
6868
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool));
69-
70-
foreach ($annotatedClasses as $class) {
71-
$this->readAllComponents($reader, $class);
69+
$throwingAutoloader = function ($class) { throw new \ReflectionException(sprintf('Class %s does not exist', $class)); };
70+
spl_autoload_register($throwingAutoloader);
71+
72+
try {
73+
foreach ($annotatedClasses as $class) {
74+
try {
75+
$this->readAllComponents($reader, $class);
76+
} catch (\ReflectionException $e) {
77+
// ignore failing reflection
78+
}
79+
}
80+
} finally {
81+
spl_autoload_unregister($throwingAutoloader);
7282
}
7383

7484
$values = $arrayPool->getValues();

src/Symfony/Component/HttpKernel/DependencyInjection/AddClassesToCachePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function getClassesInComposerClassMaps()
101101
}
102102

103103
if (is_array($function) && $function[0] instanceof ClassLoader) {
104-
$classes += $function[0]->getClassMap();
104+
$classes += array_filter($function[0]->getClassMap());
105105
}
106106
}
107107

0 commit comments

Comments
 (0)