Правило для файлов + Рекурсивное создание папки
This commit is contained in:
parent
405192f96a
commit
233e90ce72
5 changed files with 72 additions and 11 deletions
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once "core/validator/rule/all.php";
|
||||
|
||||
/**
|
||||
* Проверка коллекции
|
||||
*/
|
||||
|
|
@ -7,6 +10,10 @@ class Validator
|
|||
protected $chain = array(); // Массив правил
|
||||
protected $errorMsg = array(); // Массив ошибок
|
||||
|
||||
function __construct($rules = array()) {
|
||||
$this->addRuleList($rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление списка правил в специальном формате
|
||||
* array(array('name' => fieldname, 'validate' => ruletext), ...)
|
||||
|
|
@ -15,8 +22,6 @@ class Validator
|
|||
*/
|
||||
public function addRuleList(array $input)
|
||||
{
|
||||
require_once "core/validator/rule/all.php";
|
||||
|
||||
$type = array(
|
||||
'date' => 'Rule_Date',
|
||||
'email' => 'Rule_Email',
|
||||
|
|
@ -28,6 +33,7 @@ class Validator
|
|||
'numeric' => 'Rule_Numeric',
|
||||
'unique' => 'Rule_Unique',
|
||||
'count' => 'Rule_Count',
|
||||
'isfile' => 'Rule_IsFile',
|
||||
'code' => 'Rule_Code'
|
||||
);
|
||||
|
||||
|
|
@ -54,6 +60,8 @@ class Validator
|
|||
$rule->$name = $value;
|
||||
}
|
||||
$this->addRule($rule);
|
||||
} else {
|
||||
throw new Exception('Unknown validation rule ' . $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,17 +76,16 @@ class Validator
|
|||
}
|
||||
}
|
||||
|
||||
public function Skip($rule, $container) // -> Rule_Abstract
|
||||
public function skip($rule, $container) // -> Rule_Abstract
|
||||
{
|
||||
if ($rule instanceof Rule_Notnull) {
|
||||
return false;
|
||||
} else {
|
||||
if ($rule->skipEmpty()) {
|
||||
$data = $container->get($rule->field);
|
||||
if (!is_array($data)) {
|
||||
$value = trim($data);
|
||||
return $value == '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function validate(Collection $container, $rule = null, $status = null)
|
||||
|
|
@ -88,7 +95,7 @@ class Validator
|
|||
}
|
||||
$this->errorMsg = array();
|
||||
foreach ($this->chain as $key => $rule) {
|
||||
if (!$this->Skip($rule, $container) && !$rule->isValid($container, $status)) {
|
||||
if (!$this->skip($rule, $container) && !$rule->isValid($container, $status)) {
|
||||
$name = $rule->field;
|
||||
$this->errorMsg[$name] = $rule->getErrorMsg();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue