Skip to content

Commit

Permalink
bug #20559 [FrameworkBundle] Avoid warming up the validator cache for…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Nov 22, 2016
2 parents 2094715 + cb12f22 commit 59f9949
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -68,7 +68,9 @@ public function warmUp($cacheDir)

foreach ($this->extractSupportedLoaders($loaders) as $loader) {
foreach ($loader->getMappedClasses() as $mappedClass) {
$metadataFactory->getMetadataFor($mappedClass);
if ($metadataFactory->hasMetadataFor($mappedClass)) {
$metadataFactory->getMetadataFor($mappedClass);
}
}
}

Expand Down
Expand Up @@ -15,4 +15,15 @@
</constraint>
</property>
</class>

<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\NonExistentClass">
<property name="gender">
<constraint name="Choice">
<option name="choices">
<value>other</value>
</option>
<option name="message">This should be ignored.</option>
</constraint>
</property>
</class>
</constraint-mapping>

0 comments on commit 59f9949

Please sign in to comment.