generated from inherelab/php-pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmptyValidator.php
55 lines (48 loc) · 1008 Bytes
/
EmptyValidator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/
namespace Toolkit\PFlag\Validator;
use Toolkit\PFlag\Exception\FlagException;
use function is_string;
use function trim;
/**
* class EmptyValidator
*/
class EmptyValidator extends AbstractValidator
{
/**
* @return static
*/
public static function new(): self
{
return new static();
}
/**
* @param mixed $value
* @param string $name
*
* @return bool
*/
public function checkInput(mixed $value, string $name): bool
{
if (is_string($value)) {
$value = trim($value);
}
if (empty($value)) {
throw new FlagException("flag '$name' value cannot be empty");
}
return true;
}
/**
* @return string
*/
public function __toString(): string
{
return '';
}
}