Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88fab25

Browse files
committed
[Validator] Add pattern in Regex constraint violations
1 parent ac88f9a commit 88fab25

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.3
5+
---
6+
7+
* Add the `pattern` parameter in violations of the `Regex` constraint
8+
49
6.2
510
---
611

src/Symfony/Component/Validator/Constraints/RegexValidator.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function validate(mixed $value, Constraint $constraint)
4747
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
4848
$this->context->buildViolation($constraint->message)
4949
->setParameter('{{ value }}', $this->formatValue($value))
50+
->setParameter('{{ pattern }}', $constraint->pattern)
5051
->setCode(Regex::REGEX_FAILED_ERROR)
5152
->addViolation();
5253
}

src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function testInvalidValues($value)
118118

119119
$this->buildViolation('myMessage')
120120
->setParameter('{{ value }}', '"'.$value.'"')
121+
->setParameter('{{ pattern }}', '/^[0-9]+$/')
121122
->setCode(Regex::REGEX_FAILED_ERROR)
122123
->assertRaised();
123124
}
@@ -133,6 +134,7 @@ public function testInvalidValuesNamed($value)
133134

134135
$this->buildViolation('myMessage')
135136
->setParameter('{{ value }}', '"'.$value.'"')
137+
->setParameter('{{ pattern }}', '/^[0-9]+$/')
136138
->setCode(Regex::REGEX_FAILED_ERROR)
137139
->assertRaised();
138140
}

0 commit comments

Comments
 (0)