Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-08 18:49:06 +08:00
parent 00a53ba0f3
commit 84c345375b
13 changed files with 0 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/3 0003
* Time: 15:46
*/
declare(strict_types=1);
namespace validator;
class EmptyValidator extends BaseValidator
{
/** @var string [不能为空] */
const CAN_NOT_EMPTY = 'not empty';
/** @var string [可为空, 不能为null] */
const CAN_NOT_NULL = 'not null';
public string $method;
/**
* @return bool
*
* 检查参数是否为NULL
*/
public function trigger(): bool
{
if (empty($this->params) || !isset($this->params[$this->field])) {
return $this->addError(':attribute not exists');
}
switch (strtolower($this->method)) {
case self::CAN_NOT_EMPTY:
if (strlen($this->params[$this->field]) < 1) {
return $this->addError('The :attribute can not empty.');
}
break;
case self::CAN_NOT_NULL:
if ($this->params[$this->field] === null) {
return $this->addError('The :attribute can not is null.');
}
break;
}
return true;
}
}