bug #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 | #20720
| License       | MIT
| Doc PR        | -

Commits
-------

dcf9fbb [HttpKernel] Fix annotation cache warmer with failing or missing classes
This commit is contained in:
Nicolas Grekas 2016-12-08 16:22:53 +01:00
commit a7b5080806
2 changed files with 13 additions and 3 deletions

View File

@ -66,9 +66,19 @@ class AnnotationsCacheWarmer implements CacheWarmerInterface
$arrayPool = new ArrayAdapter(0, false);
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool));
$throwingAutoloader = function ($class) { throw new \ReflectionException(sprintf('Class %s does not exist', $class)); };
spl_autoload_register($throwingAutoloader);
foreach ($annotatedClasses as $class) {
$this->readAllComponents($reader, $class);
try {
foreach ($annotatedClasses as $class) {
try {
$this->readAllComponents($reader, $class);
} catch (\ReflectionException $e) {
// ignore failing reflection
}
}
} finally {
spl_autoload_unregister($throwingAutoloader);
}
$values = $arrayPool->getValues();

View File

@ -101,7 +101,7 @@ class AddClassesToCachePass implements CompilerPassInterface
}
if (is_array($function) && $function[0] instanceof ClassLoader) {
$classes += $function[0]->getClassMap();
$classes += array_filter($function[0]->getClassMap());
}
}