Merge branch 'noglob' of https://gitlab.edu.yar.ru/composer/PHP_Library into noglob
This commit is contained in:
commit
fd12f9a2f5
2 changed files with 25 additions and 3 deletions
21
src/Validator/Rule/PregMatch.php
Normal file
21
src/Validator/Rule/PregMatch.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
namespace ctiso\Validator\Rule;
|
||||||
|
use ctiso\Validator\Rule\AbstractRule,
|
||||||
|
ctiso\Collection;
|
||||||
|
|
||||||
|
class PregMatch extends AbstractRule
|
||||||
|
{
|
||||||
|
public $pattern;
|
||||||
|
public function getErrorMsg()
|
||||||
|
{
|
||||||
|
return "Поле в неправильном формате";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid(Collection $container, $status = null)
|
||||||
|
{
|
||||||
|
return preg_match($this->pattern,$container->get($this->field));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,8 @@ class Validator
|
||||||
'filename' => 'ctiso\\Validator\\Rule\\FileName',
|
'filename' => 'ctiso\\Validator\\Rule\\FileName',
|
||||||
'count' => 'ctiso\\Validator\\Rule\\Count',
|
'count' => 'ctiso\\Validator\\Rule\\Count',
|
||||||
'isfile' => 'ctiso\\Validator\\Rule\\IsFile',
|
'isfile' => 'ctiso\\Validator\\Rule\\IsFile',
|
||||||
'code' => 'ctiso\\Validator\\Rule\\Code'
|
'code' => 'ctiso\\Validator\\Rule\\Code',
|
||||||
|
'reg' => 'ctiso\\Validator\\Rule\\PregMatch',
|
||||||
);
|
);
|
||||||
|
|
||||||
function __construct($rules = array()) {
|
function __construct($rules = array()) {
|
||||||
|
|
@ -77,7 +78,7 @@ class Validator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRule($rule/*: any*/) {
|
public function addRule($rule/*:z any*/) {
|
||||||
if (is_array($rule)) {
|
if (is_array($rule)) {
|
||||||
$this->chain = array_merge($this->chain, $rule);
|
$this->chain = array_merge($this->chain, $rule);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -85,7 +86,7 @@ class Validator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function skip($rule/*: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
|
public function skip($rule/*z: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
|
||||||
{
|
{
|
||||||
if ($rule->skipEmpty()) {
|
if ($rule->skipEmpty()) {
|
||||||
$data = $container->get($rule->field);
|
$data = $container->get($rule->field);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue