bug #20830 [FrameworkBundle] Fix validation cache warmer with failing or missing classes (nicolas-grekas)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] Fix validation 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 | #20739
| License       | MIT
| Doc PR        | -

Commits
-------

53234e9 [FrameworkBundle] Fix validation cache warmer with failing or missing classes
This commit is contained in:
Nicolas Grekas 2016-12-08 16:21:32 +01:00
commit 2293b18c43
3 changed files with 25 additions and 6 deletions

View File

@ -66,12 +66,23 @@ class ValidatorCacheWarmer implements CacheWarmerInterface
$loaders = $this->validatorBuilder->getLoaders();
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool));
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
foreach ($loader->getMappedClasses() as $mappedClass) {
if ($metadataFactory->hasMetadataFor($mappedClass)) {
$metadataFactory->getMetadataFor($mappedClass);
$throwingAutoloader = function ($class) { throw new \ReflectionException(sprintf('Class %s does not exist', $class)); };
spl_autoload_register($throwingAutoloader);
try {
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
foreach ($loader->getMappedClasses() as $mappedClass) {
try {
if ($metadataFactory->hasMetadataFor($mappedClass)) {
$metadataFactory->getMetadataFor($mappedClass);
}
} catch (\ReflectionException $e) {
// ignore failing reflection
}
}
}
} finally {
spl_autoload_unregister($throwingAutoloader);
}
$values = $arrayPool->getValues();

View File

@ -0,0 +1,8 @@
<?php
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;
class Article implements NotExistingInterface
{
public $category;
}

View File

@ -16,8 +16,8 @@
</property>
</class>
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\NonExistentClass">
<property name="gender">
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Article">
<property name="category">
<constraint name="Choice">
<option name="choices">
<value>other</value>