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

[Validator] Throw exception if caching a non-serializable constraint #12302

Copy link
Copy link
Closed
@webmozart

Description

@webmozart
Issue body actions

Origin of this ticket:

Currently, metadata caching fails if a constraint is not serializable. The only core constraint that is susceptible to this problem is the Callback constraint when used with an object method or closure:

// OK
new Callback(array('SomeClass', 'validateMe'));
new Callback('validateMeFunction');

// Not OK
new Callback(array($this, 'validateMe'));
new Callback(function ($value, $context) { ... });

When trying to serialize the last two constraints, an error is raised (#10083) that is a little hard to debug.

Two solutions come to mind:

  • Disallow closures/objects methods in Callback and require all constraints to always be serializable. I don't quite like this, since I find passing closures to Callback very useful (e.g. in the "constraints" option of the Form component). After all, caching is not always necessary.
  • Add a method isSerializable() to Constraint. This would return true by default and false in edge cases. If caching is turned on, GenericMetadata::addConstraint() checks isSerializable() and fails if an unserializable constraint is added.

The second solution adds minor overhead (the additional function call in addConstraint()), but only if metadata is not cached. I prefer that solution since it maintains the current flexibility, but returns a useful error message when a constraint is not serializable.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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