Skip to content

Instantly share code, notes, and snippets.

@kstefan
Created July 10, 2013 12:03
Show Gist options
  • Select an option

  • Save kstefan/5965728 to your computer and use it in GitHub Desktop.

Select an option

Save kstefan/5965728 to your computer and use it in GitHub Desktop.
Callback validator example
<?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