/** * Adds a new rule for a given property or key name. * @param string $name The name of the key or property. * @param Validator $rule The validation rule. * @param string $label The label to be shown in the error message (intead of the name). */ public function addRule($name, $rule, $label = null) { if ($label === null) { $label = $name; } $rule->addKeyValue('key', $label); $this->validators[$name][] = $rule; $this->updateSingleKeyValue($rule); }
/** * Adds a new key-value pair to be replaced by the templating engine. * This does not check if it's replacing a specific validator value. * * @param string $key The key to replace (in the template as "%key%") * @param string $value The value to be inserted instead of the key. */ public function addKeyValue($key, $value) { parent::addKeyValue($key, $value); if (preg_match('/^v[0-9]+$/', $key) == 0) { foreach ($this->validators as $v) { $v->addKeyValue($key, $value); } } }