Created
July 10, 2013 12:03
-
-
Save kstefan/5965728 to your computer and use it in GitHub Desktop.
Callback validator example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function getInputFilterSpecification() | |
| { | |
| return [ | |
| 'amount' => [ | |
| 'required' => true, | |
| 'validators' => [ | |
| new Validator\GreaterThan([ | |
| 'min' => 0, | |
| 'inclusive' => false, | |
| ]), | |
| ], | |
| ], | |
| 'privateSpendingAmount' => [ | |
| 'required' => false, | |
| 'validators' => [ | |
| new Validator\GreaterThan([ | |
| 'min' => 0, | |
| 'inclusive' => true, | |
| ]), | |
| new Validator\Callback([ | |
| 'callback' => function($value, $context = []) { | |
| if ($value && $context['amount'] < $value) { | |
| return false; | |
| } | |
| return true; | |
| }, | |
| 'messages' => array( | |
| Validator\Callback::INVALID_VALUE => '__invalid-value', | |
| ), | |
| ]), | |
| ], | |
| ], | |
| ]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment