closes #3303 RFC: Rename Validator::between() into Validator::length()

This commit is contained in:
Schlaefer 2014-05-13 09:31:03 +02:00
parent d0b995ad79
commit 4848b63189
6 changed files with 14 additions and 14 deletions

View file

@ -142,8 +142,8 @@ class Model extends Object implements CakeEventListener {
* *
* {{{ * {{{
* public $validate = array( * public $validate = array(
* 'age' => array( * 'length' => array(
* 'rule' => array('between', 5, 25) * 'rule' => array('lengthBetween', 5, 25)
* ) * )
* ); * );
* }}} * }}}
@ -171,9 +171,9 @@ class Model extends Object implements CakeEventListener {
* *
* {{{ * {{{
* public $validate = array( * public $validate = array(
* 'age' => array( * 'length' => array(
* 'rule' => array('between', 5, 25), * 'rule' => array('lengthBetween', 5, 15),
* 'message' => array('The age must be between %d and %d.') * 'message' => array('Between %d to %d characters')
* ) * )
* ); * );
* }}} * }}}

View file

@ -539,7 +539,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
* ->add('user_id', 'valid', array('rule' => 'numeric', 'message' => 'Invalid User')) * ->add('user_id', 'valid', array('rule' => 'numeric', 'message' => 'Invalid User'))
* *
* $validator->add('password', array( * $validator->add('password', array(
* 'size' => array('rule' => array('between', 8, 20)), * 'size' => array('rule' => array('lengthBetween', 8, 20)),
* 'hasSpecialCharacter' => array('rule' => 'validateSpecialchar', 'message' => 'not valid') * 'hasSpecialCharacter' => array('rule' => 'validateSpecialchar', 'message' => 'not valid')
* )); * ));
* }}} * }}}

View file

@ -186,7 +186,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
* {{{ * {{{
* $set * $set
* ->setRule('required', array('rule' => 'notEmpty', 'required' => true)) * ->setRule('required', array('rule' => 'notEmpty', 'required' => true))
* ->setRule('inRange', array('rule' => array('between', 4, 10)) * ->setRule('between', array('rule' => array('lengthBetween', 4, 10))
* }}} * }}}
* *
* @param string $name The name under which the rule should be set * @param string $name The name under which the rule should be set

View file

@ -767,7 +767,7 @@ class ModelValidationTest extends BaseModelTest {
'last' => false 'last' => false
), ),
'between' => array( 'between' => array(
'rule' => array('between', 5, 15), 'rule' => array('lengthBetween', 5, 15),
'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6) 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6)
) )
) )

View file

@ -208,12 +208,12 @@ class ValidationTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testBetween() { public function testBetween() {
$this->assertTrue(Validation::between('abcdefg', 1, 7)); $this->assertTrue(Validation::lengthBetween('abcdefg', 1, 7));
$this->assertTrue(Validation::between('', 0, 7)); $this->assertTrue(Validation::lengthBetween('', 0, 7));
$this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7)); $this->assertTrue(Validation::lengthBetween('אกあアꀀ豈', 1, 7));
$this->assertFalse(Validation::between('abcdefg', 1, 6)); $this->assertFalse(Validation::lengthBetween('abcdefg', 1, 6));
$this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3)); $this->assertFalse(Validation::lengthBetween('ÆΔΩЖÇ', 1, 3));
} }
/** /**

View file

@ -104,7 +104,7 @@ class Validation {
* @param integer $max Maximum value in range (inclusive) * @param integer $max Maximum value in range (inclusive)
* @return boolean Success * @return boolean Success
*/ */
public static function between($check, $min, $max) { public static function lengthBetween($check, $min, $max) {
$length = mb_strlen($check); $length = mb_strlen($check);
return ($length >= $min && $length <= $max); return ($length >= $min && $length <= $max);
} }