[FrameworkBundle] Fix validation cache warmer with failing or missing classes

This commit is contained in:
Nicolas Grekas 2016-12-08 13:36:55 +01:00
parent f5058ac898
commit 53234e907a
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>