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

Commitd5ca7f2

Browse files
committed
[Validator] Add option to pass custom values to Expression validator
1 parentb286950 commitd5ca7f2

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.1.0
5+
-----
6+
7+
* added a`values` option to the`Expression` constraint
8+
49
4.0.0
510
-----
611

‎src/Symfony/Component/Validator/Constraints/Expression.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Expression extends Constraint
3131
public$message ='This value is not valid.';
3232
public$expression;
3333

34+
public$values = [];
35+
3436
/**
3537
* {@inheritdoc}
3638
*/

‎src/Symfony/Component/Validator/Constraints/ExpressionValidator.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint)
3939
thrownewUnexpectedTypeException($constraint,__NAMESPACE__.'\Expression');
4040
}
4141

42-
$variables =array();
42+
$variables =$constraint->values;
4343
$variables['value'] =$value;
4444
$variables['this'] =$this->context->getObject();
4545

‎src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,18 @@ public function testExpressionLanguageUsage()
270270

271271
$this->assertTrue($used,'Failed asserting that custom ExpressionLanguage instance is used.');
272272
}
273+
274+
publicfunctiontestPassingCustomValues()
275+
{
276+
$constraint =newExpression(array(
277+
'expression' =>'value + custom == 2',
278+
'values' =>array(
279+
'custom' =>1,
280+
),
281+
));
282+
283+
$this->validator->validate(1,$constraint);
284+
285+
$this->assertNoViolation();
286+
}
273287
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp