Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2293b18

Browse filesBrowse files
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
2 parents af0043b + 53234e9 commit 2293b18
Copy full SHA for 2293b18

File tree

Expand file treeCollapse file tree

3 files changed

+25
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-6
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,23 @@ public function warmUp($cacheDir)
6666
$loaders = $this->validatorBuilder->getLoaders();
6767
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool));
6868

69-
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
70-
foreach ($loader->getMappedClasses() as $mappedClass) {
71-
if ($metadataFactory->hasMetadataFor($mappedClass)) {
72-
$metadataFactory->getMetadataFor($mappedClass);
69+
$throwingAutoloader = function ($class) { throw new \ReflectionException(sprintf('Class %s does not exist', $class)); };
70+
spl_autoload_register($throwingAutoloader);
71+
72+
try {
73+
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
74+
foreach ($loader->getMappedClasses() as $mappedClass) {
75+
try {
76+
if ($metadataFactory->hasMetadataFor($mappedClass)) {
77+
$metadataFactory->getMetadataFor($mappedClass);
78+
}
79+
} catch (\ReflectionException $e) {
80+
// ignore failing reflection
81+
}
7382
}
7483
}
84+
} finally {
85+
spl_autoload_unregister($throwingAutoloader);
7586
}
7687

7788
$values = $arrayPool->getValues();
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation;
4+
5+
class Article implements NotExistingInterface
6+
{
7+
public $category;
8+
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Resources/person.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Resources/person.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</property>
1717
</class>
1818

19-
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\NonExistentClass">
20-
<property name="gender">
19+
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Article">
20+
<property name="category">
2121
<constraint name="Choice">
2222
<option name="choices">
2323
<value>other</value>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.