-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Validator cache and closure #19937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The exception is thrown when /**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
//It's OK !
$fakeNames = array('fake-name');
if (in_array($this->getFirstName(), $fakeNames)) {
$context->buildViolation('This name sounds totally fake!')
->atPath('firstName')
->addViolation();
}
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
//Exception is thrown !!!!
/*
* Uncaught PHP Exception Exception: "Serialization of 'Closure' is not allowed" at
* /path/vendor/doctrine/cache/lib/Doctrine/Common/Cache/ApcCache.php line 57 {"exception":"[object]
* (Exception(code: 0): Serialization of 'Closure' is not allowed
*/
$callback = function ($object, ExecutionContextInterface $context, $payload) {
// ...
};
$metadata->addConstraint(new Assert\Callback($callback));
} You can test here : https://github.com/hlecorche/bug-closure (homepage route in prod environment) |
if you want your metadata to be cacheable, don't use a closure for the callback. |
Closing here as #20793 has been merged. Please comment with some more details if you still experience any issues. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In validator component, a metadata object can have a closure.
But when
framework.validation.cache
is used withvalidator.mapping.cache.doctrine.apc
, the cache throws an exception because cache can't seraliaze a closure.The text was updated successfully, but these errors were encountered: