Validate an array of discrete values

This commit is contained in:
Mark Cahill 2014-09-08 12:34:46 -04:00
parent d71a928c60
commit eace42656a
2 changed files with 12 additions and 0 deletions

View File

@ -803,6 +803,11 @@ class Validator
protected function getPart($data, $identifiers)
{
// Catches the case where the field is an array of discrete values
if (is_array($identifiers) && count($identifiers) === 0) {
return array($data, false);
}
$identifier = array_shift($identifiers);
// Glob match

View File

@ -308,6 +308,13 @@ class ValidateTest extends BaseTestCase
$this->assertFalse($v->validate());
}
public function testForeachDiscreteValues()
{
$v = new Validator(array('values' => array(5, 10, 15, 20, 25)));
$v->rule('integer', 'values.*');
$this->assertTrue($v->validate());
}
public function testForeachArrayAccess()
{
$v = new Validator(array('settings' => array(