Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add strict parameter to inList() and multiple()

  • Loading branch information...
commit fe0c7d348a8d4cb0ec6ce2bf083d6b9f9c6aa928 1 parent 388053c
@ceeram ceeram authored
View
4 lib/Cake/Test/Case/Utility/ValidationTest.php
@@ -1822,6 +1822,8 @@ public function testInList() {
$this->assertFalse(Validation::inList('three', array('one', 'two')));
$this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3)));
$this->assertFalse(Validation::inList('one', array(0, 1, 2, 3)));
+ $this->assertFalse(Validation::inList('2', array(1, 2, 3)));
+ $this->assertTrue(Validation::inList('2', array(1, 2, 3), false));
}
/**
@@ -1932,6 +1934,8 @@ public function testMultiple() {
$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('min' => 10)));
$this->assertTrue(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5)));
+ $this->assertFalse(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5)));
+ $this->assertTrue(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5), false));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5)));
View
10 lib/Cake/Utility/Validation.php
@@ -527,9 +527,10 @@ public static function money($check, $symbolPosition = 'left') {
*
* @param mixed $check Value to check
* @param mixed $options Options for the check.
+ * @param boolean $strict Defaults to true, set to false to disable strict type check
* @return boolean Success
*/
- public static function multiple($check, $options = array()) {
+ public static function multiple($check, $options = array(), $strict = true) {
$defaults = array('in' => null, 'max' => null, 'min' => null);
$options = array_merge($defaults, $options);
$check = array_filter((array)$check);
@@ -544,7 +545,7 @@ public static function multiple($check, $options = array()) {
}
if ($options['in'] && is_array($options['in'])) {
foreach ($check as $val) {
- if (!in_array($val, $options['in'], true)) {
+ if (!in_array($val, $options['in'], $strict)) {
return false;
}
}
@@ -716,10 +717,11 @@ public static function url($check, $strict = false) {
*
* @param string $check Value to check
* @param array $list List to check against
+ * @param boolean $strict Defaults to true, set to false to disable strict type check
* @return boolean Success
*/
- public static function inList($check, $list) {
- return in_array($check, $list, true);
+ public static function inList($check, $list, $strict = true) {
+ return in_array($check, $list, $strict);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.