Files

44 lines
809 B
PHP
Raw Permalink Normal View History

2022-01-09 14:01:11 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/3 0003
* Time: 15:46
*/
declare(strict_types=1);
namespace validator;
2023-10-24 17:22:29 +08:00
/**
*
*/
2022-01-09 14:01:11 +08:00
class EmptyValidator extends BaseValidator
{
2022-02-18 17:16:45 +08:00
2023-07-07 17:24:03 +08:00
/** @var string [不能为空] */
2023-12-12 15:35:34 +08:00
const string CAN_NOT_EMPTY = 'not empty';
2022-02-18 17:16:45 +08:00
2023-07-07 17:24:03 +08:00
/** @var string [可为空, 不能为null] */
2023-12-12 15:35:34 +08:00
const string CAN_NOT_NULL = 'not null';
2022-01-09 14:01:11 +08:00
2023-07-07 17:24:03 +08:00
public string $method;
2022-02-18 17:16:45 +08:00
2023-05-09 10:11:21 +08:00
/**
2023-12-18 15:01:09 +08:00
* @param mixed $value
2023-05-09 10:11:21 +08:00
* @return bool
*
* 检查参数是否为NULL
*/
2023-12-19 14:51:13 +08:00
public function trigger(mixed $value): bool
2023-07-07 17:24:03 +08:00
{
2023-12-18 15:01:09 +08:00
return match ($this->method) {
self::CAN_NOT_NULL => !is_null($value),
self::CAN_NOT_EMPTY => !empty($value),
default => true
};
2023-07-07 17:24:03 +08:00
}
2022-01-09 14:01:11 +08:00
}