Skip to content
Permalink
Browse files

Improving docs for CakeValidationSet

  • Loading branch information...
lorenzo committed May 11, 2012
1 parent 8c9c6b4 commit c4202b7b22eecc9605c52d070cd5d07b3acf9d04
Showing with 44 additions and 18 deletions.
  1. +44 −18 lib/Cake/Model/Validator/CakeValidationSet.php
@@ -30,14 +30,14 @@
class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
/**
* Holds the ValidationRule objects
* Holds the CakeValidationRule objects
*
* @var array
*/
protected $_rules = array();
/**
* Set of methods available for validation
* List of methods available for validation
*
* @var array
**/
@@ -51,7 +51,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
protected $_validationDomain = null;
/**
* If the validation is stopped
* Whether the validation is stopped
*
* @var boolean
*/
@@ -110,7 +110,8 @@ public function setValidationDomain($validationDomain) {
}
/**
* Validates a ModelField
* Runs all validation rules in this set and returns a list of
* validation errors
*
* @return array list of validation errors for this field
*/
@@ -142,19 +143,19 @@ public function validate($data, $isUpdate = false) {
}
/**
* Gets a rule for a certain index
* Gets a rule for a given name if exists
*
* @param mixed index
* @return ValidationRule
* @param string $name
* @return CakeValidationRule
*/
public function getRule($index) {
if (!empty($this->_rules[$index])) {
return $this->_rules[$index];
public function getRule($name) {
if (!empty($this->_rules[$name])) {
return $this->_rules[$name];
}
}
/**
* Gets all rules for this ModelField
* Returns all rules for this validation set
*
* @return array
*/
@@ -163,34 +164,59 @@ public function getRules() {
}
/**
* Sets a ValidationRule $rule for key $key
* Sets a CakeValidationRule $rule with a $name
*
* ## Example:
*
* @param mixed $key The key under which the rule should be set
* {{{
* $set
* ->setRule('required', array('rule' => 'notEmpty', 'required' => true))
* ->setRule('inRange', array('rule' => array('between', 4, 10))
* }}}
*
* @param mixed $name The name under which the rule should be set
* @param CakeValidationRule|array $rule The validation rule to be set
* @return CakeValidationSet this instance
*/
public function setRule($key, $rule) {
public function setRule($name, $rule) {
if (!$rule instanceof CakeValidationRule) {
$rule = new CakeValidationRule($rule);
}
$this->_rules[$key] = $rule;
$this->_rules[$name] = $rule;
return $this;
}
/**
* Removes a validation rule from the set
*
* @param mixed $key The key under which the rule should be unset
* ## Example:
*
* {{{
* $set
* ->removeRule('required')
* ->removeRule('inRange')
* }}}
*
* @param mixed $name The name under which the rule should be unset
* @return CakeValidationSet this instance
*/
public function removeRule($key) {
unset($this->_rules[$key]);
public function removeRule($name) {
unset($this->_rules[$name]);
return $this;
}
/**
* Sets the rules for a given field
*
* ## Example:
*
* {{{
* $set->setRules(array(
* 'required' => array('rule' => 'notEmpty', 'required' => true),
* 'inRange' => array('rule' => array('between', 4, 10)
* ));
* }}}
*
* @param array $rules The rules to be set
* @param bolean $mergeVars [optional] If true, merges vars instead of replace. Defaults to true.
* @return ModelField

0 comments on commit c4202b7

Please sign in to comment.
You can’t perform that action at this time.