class SerializedConstraintValidator
Validates the Serialized constraint.
Hierarchy
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\SerializedConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of SerializedConstraintValidator
1 file declares its use of SerializedConstraintValidator
- SerializedConstraintValidatorTest.php in core/
tests/ Drupal/ Tests/ Core/ Validation/ Plugin/ Validation/ Constraint/ SerializedConstraintValidatorTest.php
File
-
core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ SerializedConstraintValidator.php, line 11
Namespace
Drupal\Core\Validation\Plugin\Validation\ConstraintView source
class SerializedConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) : void {
if (!isset($value)) {
return;
}
if (!is_string($value)) {
$this->context
->addViolation($constraint->wrongTypeMessage, [
'{type}' => gettype($value),
]);
return;
}
// Unserialize will return false if unserializing "false". It will also
// return false if unserialization fails. Handle this edge case.
if ('b:0;' === $value) {
return;
}
$unserialized = @unserialize($value, [
'allowed_classes' => FALSE,
]);
if ($unserialized === FALSE) {
$this->context
->addViolation($constraint->message);
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.