<?php
use Chubbyphp\Validation\Constraint\NumericConstraint;
use Chubbyphp\Validation\ValidatorContextInterface;
$constraint = new NumericConstraint();
/** @var ValidatorContextInterface $context */
$context = ...;
// Use NotNullConstraint to prevent null
$errors = $constraint->validate(
'path.to.property',
null,
$context
);
// [];
// Use NotBlankConstraint to prevent ''
$errors = $constraint->validate(
'path.to.property',
'',
$context
);
// [];
$errors = $constraint->validate(
'path.to.property',
1,
$context
);
// [];
$errors = $constraint->validate(
'path.to.property',
1.1,
$context
);
// [];
$errors = $constraint->validate(
'path.to.property',
'1.1',
$context
);
// [];
$errors = $constraint->validate(
'path.to.property',
[],
$context
);
// [
// new Error(
// 'path.to.property',
// 'constraint.numeric.invalidtype',
// ['type' => 'array']
// )
// ];
$errors = $constraint->validate(
'path.to.property',
'email',
$context
);
// [
// new Error(
// 'path.to.property',
// 'constraint.numeric.notnumeric',
// ['value' => 'email']
// )
// ];
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.