Files
kiri-validator/ArrayValidator.php
T

40 lines
689 B
PHP
Raw Normal View History

2022-01-09 14:01:11 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/3 0003
* Time: 15:28
*/
declare(strict_types=1);
namespace validator;
2023-05-09 10:17:10 +08:00
use ReflectionException;
2022-01-09 14:01:11 +08:00
/**
* Class ArrayValidator
* @package validator
*/
class ArrayValidator extends BaseValidator
{
2023-05-09 10:17:10 +08:00
/**
* @return bool
*
* 检查
* @throws ReflectionException
*/
2022-01-09 14:01:11 +08:00
public function trigger(): bool
{
2022-02-18 17:16:45 +08:00
return $this->_validator($this->field, function ($field, $params) {
$value = $params[$field] ?? null;
if (!is_array($value)) {
2022-02-25 17:12:15 +08:00
return $this->addError($field, 'The param :attribute must a array');
2022-02-18 17:16:45 +08:00
}
return true;
}, $this->params);
2022-01-09 14:01:11 +08:00
}
}