[FrameworkBundle] Fix validation cache warmer with failing or missing classes
This commit is contained in:
parent
f5058ac898
commit
53234e907a
@ -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();
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;
|
||||
|
||||
class Article implements NotExistingInterface
|
||||
{
|
||||
public $category;
|
||||
}
|
@ -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>
|
||||
|
Reference in New Issue
Block a user