Версия полностью совместимая c CMS
This commit is contained in:
parent
7ce493414e
commit
75bb35d5bf
21 changed files with 1404 additions and 783 deletions
|
|
@ -32,7 +32,8 @@ class Validator_Validator
|
|||
'require' => 'Validator_Rule_Notnull',
|
||||
'numeric' => 'Validator_Rule_Numeric',
|
||||
'unique' => 'Validator_Rule_Unique',
|
||||
'count' => 'Validator_Rule_Count',
|
||||
'filename' => 'Validator_Rule_FileName',
|
||||
'count' => 'Validator_Rule_Count',
|
||||
'isfile' => 'Validator_Rule_IsFile',
|
||||
'code' => 'Validator_Rule_Code'
|
||||
);
|
||||
|
|
@ -41,8 +42,7 @@ class Validator_Validator
|
|||
// Формат правила 'rule1|rule2,param1=value1|rule3,param1=value1,param2=value2'
|
||||
foreach ($input as $value) {
|
||||
// Список правил
|
||||
if (!isset($value['validate']) || $value['validate'] == '') continue;
|
||||
|
||||
if (! isset($value['validate'])) continue;
|
||||
$rules = explode("|", $value['validate']);
|
||||
foreach ($rules as $rule) {
|
||||
// Список параметров правила
|
||||
|
|
@ -50,17 +50,17 @@ class Validator_Validator
|
|||
$name = array_shift($rule_param);
|
||||
|
||||
if (isset($type[$name])) {
|
||||
$constructor = $type[$name]; // "Rule_" . ucfirst($name)
|
||||
$rule = new $constructor($value['name'], false); // Нужны шаблонные сообщения для правил
|
||||
$constructor = $type[$name];
|
||||
$ruleObj = new $constructor($value['name'], false); // Нужны шаблонные сообщения для правил
|
||||
if (isset($value['context'])) {
|
||||
$rule->setContext($value['context']);
|
||||
$ruleObj->setContext($value['context']);
|
||||
}
|
||||
foreach ($rule_param as $param) {
|
||||
// Имя и значение параметра
|
||||
list($name, $value) = explode("=", $param);
|
||||
$rule->$name = $value;
|
||||
list($p_name, $p_value) = explode("=", $param);
|
||||
$ruleObj->$p_name = $p_value;
|
||||
}
|
||||
$this->addRule($rule);
|
||||
$this->addRule($ruleObj);
|
||||
} else {
|
||||
throw new Exception('Unknown validation rule "' . $rule . "'");
|
||||
}
|
||||
|
|
@ -90,14 +90,17 @@ class Validator_Validator
|
|||
|
||||
public function validate(Collection $container, $rule = null, $status = null)
|
||||
{
|
||||
$fields = array();
|
||||
if ($rule) {
|
||||
$this->chain = $rule;
|
||||
}
|
||||
$this->errorMsg = array();
|
||||
foreach ($this->chain as $key => $rule) {
|
||||
if (!$this->skip($rule, $container) && !$rule->isValid($container, $status)) {
|
||||
foreach ($this->chain as $rule) {
|
||||
//echo $key;
|
||||
if (!in_array($rule->field, $fields) && !$this->skip($rule, $container) && !$rule->isValid($container, $status)) {
|
||||
$name = $rule->field;
|
||||
$this->errorMsg[$name] = $rule->getErrorMsg();
|
||||
$fields [] = $name;
|
||||
}
|
||||
}
|
||||
return $this->isValid();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue