mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Fix #115 strict flag for in_array
This commit is contained in:
parent
bd0f6868c8
commit
e6273c129f
@ -350,13 +350,18 @@ class Validator
|
||||
* @internal param array $fields
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateIn($field, $value, $params, $strict = false)
|
||||
protected function validateIn($field, $value, $params)
|
||||
{
|
||||
$isAssoc = array_values($params[0]) !== $params[0];
|
||||
if ($isAssoc) {
|
||||
$params[0] = array_keys($params[0]);
|
||||
}
|
||||
|
||||
$strict = false;
|
||||
if (isset($params[1])) {
|
||||
$strict = $params[1];
|
||||
}
|
||||
|
||||
return in_array($value, $params[0], $strict);
|
||||
}
|
||||
|
||||
|
||||
@ -273,6 +273,13 @@ class ValidateTest extends BaseTestCase
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testInStrictInvalid()
|
||||
{
|
||||
$v = new Validator(array('color' => '1'));
|
||||
$v->rule('in', 'color', array(1, 2, 3), true);
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testArrayValid()
|
||||
{
|
||||
$v = new Validator(array('colors' => array('yellow')));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user