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

Commitc62d94c

Browse files
author
Peter Bouwdewijn
committed
[Validator] Added context object method callback to choice validator
1 parent98051e9 commitc62d94c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function validate($value, Constraint $constraint)
4848

4949
if ($constraint->callback) {
5050
if (!is_callable($choices =array($this->context->getClassName(),$constraint->callback))
51+
&& !is_callable($choices =array($this->context->getObject(),$constraint->callback))
5152
&& !is_callable($choices =$constraint->callback)
5253
) {
5354
thrownewConstraintDefinitionException('The Choice constraint expects a valid callback');

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static function staticCallback()
3232
returnarray('foo','bar');
3333
}
3434

35+
publicfunctionobjectMethodCallback()
36+
{
37+
returnarray('foo','bar');
38+
}
39+
3540
/**
3641
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
3742
*/
@@ -118,6 +123,18 @@ public function testValidChoiceCallbackContextMethod()
118123
$this->assertNoViolation();
119124
}
120125

126+
publicfunctiontestValidChoiceCallbackContextObjectMethod()
127+
{
128+
// search $this for "objectMethodCallback"
129+
$this->setObject($this);
130+
131+
$constraint =newChoice(array('callback' =>'objectMethodCallback'));
132+
133+
$this->validator->validate('bar',$constraint);
134+
135+
$this->assertNoViolation();
136+
}
137+
121138
publicfunctiontestMultipleChoices()
122139
{
123140
$constraint =newChoice(array(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp