class YamlValidator
@author Kev <https://github.com/symfonyaml>
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
- class \Symfony\Component\Validator\Constraints\YamlValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of YamlValidator
File
-
vendor/
symfony/ validator/ Constraints/ YamlValidator.php, line 24
Namespace
Symfony\Component\Validator\ConstraintsView source
class YamlValidator extends ConstraintValidator {
public function validate(mixed $value, Constraint $constraint) : void {
if (!$constraint instanceof Yaml) {
throw new UnexpectedTypeException($constraint, Yaml::class);
}
if (null === $value || '' === $value) {
return;
}
if (!\is_scalar($value) && !$value instanceof \Stringable) {
throw new UnexpectedValueException($value, 'string');
}
$value = (string) $value;
/** @see \Symfony\Component\Yaml\Command\LintCommand::validate() */
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
if (\E_USER_DEPRECATED === $level) {
throw new ParseException($message, $this->getParser()
->getRealCurrentLineNb() + 1);
}
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
});
try {
(new Parser())->parse($value, $constraint->flags);
} catch (ParseException $e) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ error }}', $e->getMessage())
->setParameter('{{ line }}', $e->getParsedLine())
->setCode(Yaml::INVALID_YAML_ERROR)
->addViolation();
} finally {
restore_error_handler();
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ConstraintValidator::$context | protected | property | ||
ConstraintValidator::formatTypeOf | protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator::formatValue | protected | function | Returns a string representation of the value. | |
ConstraintValidator::formatValues | protected | function | Returns a string representation of a list of values. | |
ConstraintValidator::initialize | public | function | Initializes the constraint validator. | Overrides ConstraintValidatorInterface::initialize |
ConstraintValidator::OBJECT_TO_STRING | public | constant | Whether to cast objects with a "__toString()" method to strings. | |
ConstraintValidator::PRETTY_DATE | public | constant | Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s"). |
|
YamlValidator::validate | public | function | Checks if the passed value is valid. | Overrides ConstraintValidatorInterface::validate |