Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit222910f

Browse files
committed
[Validator] AddFinite constraint
1 parent6c85287 commit222910f

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

‎src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Allow single integer for the`versions` option of the`Uuid` constraint
88
* Allow single constraint to be passed to the`constraints` option of the`When` constraint
9+
* Add`Finite` contraint
910

1011
6.3
1112
---
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Constraint;
15+
16+
/**
17+
* @Annotation
18+
*
19+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
20+
*
21+
* @author Guillaume Aveline <guillaume@codr.fr>
22+
*/
23+
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
24+
class Finiteextends Constraint
25+
{
26+
publicconstNOT_FINITE_ERROR ='5f809eb0-78b9-492d-ad37-5a5188390415';
27+
28+
protectedconstERROR_NAMES = [
29+
self::NOT_FINITE_ERROR =>'NOT_FINITE_ERROR',
30+
];
31+
32+
public$message ='This value should be finite.';
33+
34+
publicfunction__construct(string$message =null,array$groups =null,mixed$payload =null,array$options = [])
35+
{
36+
parent::__construct($options,$groups,$payload);
37+
38+
$this->message =$message ??$this->message;
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Constraint;
15+
useSymfony\Component\Validator\ConstraintValidator;
16+
useSymfony\Component\Validator\Exception\UnexpectedTypeException;
17+
18+
/**
19+
* @author Guillaume Aveline <guillaume@codr.fr>
20+
*/
21+
class FiniteValidatorextends ConstraintValidator
22+
{
23+
publicfunctionvalidate(mixed$value,Constraint$constraint):void
24+
{
25+
if (!$constraintinstanceof Finite) {
26+
thrownewUnexpectedTypeException($constraint, Finite::class);
27+
}
28+
29+
if (null ===$value) {
30+
return;
31+
}
32+
33+
if(is_finite($value)) {
34+
return;
35+
}
36+
37+
$this->context->buildViolation($constraint->message)
38+
->setParameter('{{ value }}',$this->formatValue($value))
39+
->setCode(Finite::NOT_FINITE_ERROR)
40+
->addViolation();
41+
}
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp