Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59f9949

Browse files
committed
bug #20559 [FrameworkBundle] Avoid warming up the validator cache for non-existent class (Seldaek)
This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #20559). Discussion ---------- [FrameworkBundle] Avoid warming up the validator cache for non-existent class | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? |no | Tests pass? | yes | License | MIT This relates to FriendsOfSymfony/FOSUserBundle#2224 - where basically the cache warmer triggers autoloading of a class that is broken, and it then blows up. This doesn't fix the problem in itself, loading broken classes will still fail, but it allows us at least to work around it by doing: ``` "exclude-from-classmap": [ "vendor/friendsofsymfony/user-bundle/Propel/" ] ``` And then `composer dump-autoload -a` to get an authoritative classmap. That way the hasMetadataFor will return false because class_exist() won't try to load the class at all. Without the hasMetadataFor fix though, it calls getMetadataFor which throws an exception in the case the class doesn't exist. I am not sure if that's by design.. that the cache warmer would force you to have classes existing for all your validation definitions. Commits ------- cb12f22 [FrameworkBundle] Avoid warming up the validator cache for non-existent classes
2 parents 2094715 + cb12f22 commit 59f9949

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public function warmUp($cacheDir)
6868

6969
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
7070
foreach ($loader->getMappedClasses() as $mappedClass) {
71-
$metadataFactory->getMetadataFor($mappedClass);
71+
if ($metadataFactory->hasMetadataFor($mappedClass)) {
72+
$metadataFactory->getMetadataFor($mappedClass);
73+
}
7274
}
7375
}
7476

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@
1515
</constraint>
1616
</property>
1717
</class>
18+
19+
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\NonExistentClass">
20+
<property name="gender">
21+
<constraint name="Choice">
22+
<option name="choices">
23+
<value>other</value>
24+
</option>
25+
<option name="message">This should be ignored.</option>
26+
</constraint>
27+
</property>
28+
</class>
1829
</constraint-mapping>

0 commit comments

Comments
 (0)