diff --git a/lib/Cake/Cache/Engine/MemcachedEngine.php b/lib/Cake/Cache/Engine/MemcachedEngine.php index 9c50186fe..820dd720f 100644 --- a/lib/Cake/Cache/Engine/MemcachedEngine.php +++ b/lib/Cake/Cache/Engine/MemcachedEngine.php @@ -45,6 +45,8 @@ class MemcachedEngine extends CacheEngine { * - serialize = string, default => php. The serializer engine used to serialize data. * Available engines are php, igbinary and json. Beside php, the memcached extension * must be compiled with the appropriate serializer support. + * - options - Additional options for the memcached client. Should be an array of option => value. + * Use the Memcached::OPT_* constants as keys. * * @var array */ @@ -92,7 +94,8 @@ class MemcachedEngine extends CacheEngine { 'persistent' => false, 'login' => null, 'password' => null, - 'serialize' => 'php' + 'serialize' => 'php', + 'options' => array() ); parent::init($settings); @@ -128,6 +131,11 @@ class MemcachedEngine extends CacheEngine { } $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']); } + if (is_array($this->settings['options'])) { + foreach ($this->settings['options'] as $opt => $value) { + $this->_Memcached->setOption($opt, $value); + } + } return true; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 0d6c19594..76160262e 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -142,8 +142,8 @@ class Model extends Object implements CakeEventListener { * * {{{ * public $validate = array( - * 'age' => array( - * 'rule' => array('between', 5, 25) + * 'length' => array( + * 'rule' => array('lengthBetween', 5, 25) * ) * ); * }}} @@ -171,9 +171,9 @@ class Model extends Object implements CakeEventListener { * * {{{ * public $validate = array( - * 'age' => array( - * 'rule' => array('between', 5, 25), - * 'message' => array('The age must be between %d and %d.') + * 'length' => array( + * 'rule' => array('lengthBetween', 5, 15), + * 'message' => array('Between %d to %d characters') * ) * ); * }}} diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index d61ba8b66..377866aa9 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -539,7 +539,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { * ->add('user_id', 'valid', array('rule' => 'numeric', 'message' => 'Invalid User')) * * $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') * )); * }}} diff --git a/lib/Cake/Model/Validator/CakeValidationSet.php b/lib/Cake/Model/Validator/CakeValidationSet.php index 80b9a79cc..e6817e50c 100644 --- a/lib/Cake/Model/Validator/CakeValidationSet.php +++ b/lib/Cake/Model/Validator/CakeValidationSet.php @@ -186,7 +186,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { * {{{ * $set * ->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 diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php index 6ae5e3896..748db0079 100644 --- a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php @@ -103,7 +103,8 @@ class MemcachedEngineTest extends CakeTestCase { 'login' => null, 'password' => null, 'groups' => array(), - 'serialize' => 'php' + 'serialize' => 'php', + 'options' => array() ); $this->assertEquals($expecting, $settings); } @@ -133,6 +134,23 @@ class MemcachedEngineTest extends CakeTestCase { $this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); } +/** + * test setting options + * + * @return void + */ + public function testOptionsSetting() { + $memcached = new TestMemcachedEngine(); + $memcached->init(array( + 'engine' => 'Memcached', + 'servers' => array('127.0.0.1:11211'), + 'options' => array( + Memcached::OPT_BINARY_PROTOCOL => true + ) + )); + $this->assertEquals(1, $memcached->getMemcached()->getOption(Memcached::OPT_BINARY_PROTOCOL)); + } + /** * test accepts only valid serializer engine * diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index a6b57dbd2..ce2258bb8 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -315,7 +315,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->initValidations(); $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('24', 'y', '18', 'n')); + ->will($this->onConsecutiveCalls('25', 'y', '19', 'n')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength'); @@ -333,7 +333,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('999999', '24', 'n')); + ->will($this->onConsecutiveCalls('999999', '25', 'n')); $this->Task->expects($this->at(10))->method('out') ->with($this->stringContains('make a valid')); @@ -368,7 +368,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->initValidations(); $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('24', 'y', 's')); + ->will($this->onConsecutiveCalls('25', 'y', 's')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true); @@ -384,7 +384,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->initValidations(); $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('24', 's')); + ->will($this->onConsecutiveCalls('25', 's')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true); @@ -400,7 +400,7 @@ class ModelTaskTest extends CakeTestCase { public function testInteractiveDoValidationWithSkipping() { $this->Task->expects($this->any()) ->method('in') - ->will($this->onConsecutiveCalls('35', '24', 'n', '11', 's')); + ->will($this->onConsecutiveCalls('36', '25', 'n', '11', 's')); $this->Task->interactive = true; $Model = $this->getMock('Model'); $Model->primaryKey = 'id'; diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index 8a3d266fd..b04bbb46d 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -767,7 +767,7 @@ class ModelValidationTest extends BaseModelTest { 'last' => false ), '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) ) ) @@ -1844,7 +1844,7 @@ class ModelValidationTest extends BaseModelTest { $set = array( 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), - 'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), + 'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false), ); $Validator['other'] = $set; $rules = $Validator['other']; @@ -1853,7 +1853,7 @@ class ModelValidationTest extends BaseModelTest { $validators = $rules->getRules(); $this->assertCount(2, $validators); $this->assertEquals('numeric', $validators['numeric']->rule); - $this->assertEquals(array('between', 1, 5), $validators['range']->rule); + $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule); $Validator['new'] = new CakeValidationSet('new', $set, array()); $rules = $Validator['new']; @@ -1862,7 +1862,7 @@ class ModelValidationTest extends BaseModelTest { $validators = $rules->getRules(); $this->assertCount(2, $validators); $this->assertEquals('numeric', $validators['numeric']->rule); - $this->assertEquals(array('between', 1, 5), $validators['range']->rule); + $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule); } /** @@ -1917,7 +1917,7 @@ class ModelValidationTest extends BaseModelTest { $set = array( 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), - 'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), + 'range' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false), ); $Validator['other'] = $set; $this->assertCount(4, $Validator); @@ -1938,14 +1938,14 @@ class ModelValidationTest extends BaseModelTest { $Validator = $TestModel->validator(); $Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false)); - $Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false)); + $Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false)); $rules = $Validator['other']; $this->assertEquals('other', $rules->field); $validators = $rules->getRules(); $this->assertCount(2, $validators); $this->assertEquals('numeric', $validators['numeric']->rule); - $this->assertEquals(array('between', 1, 5), $validators['range']->rule); + $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule); } /** @@ -1962,13 +1962,13 @@ class ModelValidationTest extends BaseModelTest { $this->assertFalse(isset($Validator['title'])); $Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false)); - $Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false)); + $Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false)); $this->assertTrue(isset($Validator['other'])); $Validator->remove('other', 'numeric'); $this->assertTrue(isset($Validator['other'])); $this->assertFalse(isset($Validator['other']['numeric'])); - $this->assertTrue(isset($Validator['other']['range'])); + $this->assertTrue(isset($Validator['other']['between'])); } /** @@ -2126,7 +2126,7 @@ class ModelValidationTest extends BaseModelTest { $set = array( 'numeric' => array('rule' => 'numeric', 'allowEmpty' => false), - 'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), + 'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false), ); $Validator->add('other', $set); @@ -2136,11 +2136,11 @@ class ModelValidationTest extends BaseModelTest { $validators = $rules->getRules(); $this->assertCount(2, $validators); $this->assertEquals('numeric', $validators['numeric']->rule); - $this->assertEquals(array('between', 1, 5), $validators['range']->rule); + $this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule); $set = new CakeValidationSet('other', array( 'a' => array('rule' => 'numeric', 'allowEmpty' => false), - 'b' => array('rule' => array('between', 1, 5), 'allowEmpty' => false), + 'b' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false), )); $Validator->add('other', $set); diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index abfe502cf..401d4388e 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -203,17 +203,17 @@ class ValidationTest extends CakeTestCase { } /** - * testBetween method + * testLengthBetween method * * @return void */ - public function testBetween() { - $this->assertTrue(Validation::between('abcdefg', 1, 7)); - $this->assertTrue(Validation::between('', 0, 7)); - $this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7)); + public function testLengthBetween() { + $this->assertTrue(Validation::lengthBetween('abcdefg', 1, 7)); + $this->assertTrue(Validation::lengthBetween('', 0, 7)); + $this->assertTrue(Validation::lengthBetween('אกあアꀀ豈', 1, 7)); - $this->assertFalse(Validation::between('abcdefg', 1, 6)); - $this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3)); + $this->assertFalse(Validation::lengthBetween('abcdefg', 1, 6)); + $this->assertFalse(Validation::lengthBetween('ÆΔΩЖÇ', 1, 3)); } /** diff --git a/lib/Cake/Test/test_app/Model/Extract.php b/lib/Cake/Test/test_app/Model/Extract.php index 0cd7218c4..2c5469055 100644 --- a/lib/Cake/Test/test_app/Model/Extract.php +++ b/lib/Cake/Test/test_app/Model/Extract.php @@ -36,7 +36,7 @@ class Extract extends AppModel { 'message' => 'double "quoted" validation' ), 'between' => array( - 'rule' => array('between', 5, 15), + 'rule' => array('lengthBetween', 5, 15), 'message' => "single 'quoted' validation" ) ), diff --git a/lib/Cake/Test/test_app/Model/PersisterOne.php b/lib/Cake/Test/test_app/Model/PersisterOne.php index 0a14b0f4a..e5c699945 100644 --- a/lib/Cake/Test/test_app/Model/PersisterOne.php +++ b/lib/Cake/Test/test_app/Model/PersisterOne.php @@ -38,7 +38,7 @@ class PersisterOne extends AppModel { 'message' => 'Post title is required' ), '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) ) ), diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index a2d08bb65..b7c7b9464 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -104,11 +104,25 @@ class Validation { * @param integer $max Maximum value in range (inclusive) * @return boolean Success */ - public static function between($check, $min, $max) { + public static function lengthBetween($check, $min, $max) { $length = mb_strlen($check); return ($length >= $min && $length <= $max); } +/** + * Alias of Validator::lengthBetween() for backwards compatibility. + * + * @see Validator::lengthBetween() + * @deprecated Deprecated since 2.6, use Validator::lengthBetween() instead. + * @param string $check Value to check for length + * @param integer $min Minimum value in range (inclusive) + * @param integer $max Maximum value in range (inclusive) + * @return boolean Success + */ + public static function between($check, $min, $max) { + return self::lengthBetween($check, $min, $max); + } + /** * Returns true if field is left blank -OR- only whitespace characters are present in its value * Whitespace characters include Space, Tab, Carriage Return, Newline