1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Smoren\Validator\Rules; |
6
|
|
|
|
7
|
|
|
use Smoren\Validator\Factories\Checks\StringCheckFactory; |
8
|
|
|
use Smoren\Validator\Interfaces\IntegerRuleInterface; |
9
|
|
|
use Smoren\Validator\Interfaces\StringRuleInterface; |
10
|
|
|
|
11
|
|
|
class StringRule extends MixedRule implements StringRuleInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string $name |
15
|
|
|
*/ |
16
|
26 |
|
public function __construct(string $name) |
17
|
|
|
{ |
18
|
26 |
|
parent::__construct($name); |
19
|
26 |
|
$this->check(StringCheckFactory::getStringCheck(), true); |
20
|
|
|
} |
21
|
|
|
|
22
|
2 |
|
public function numeric(): StringRuleInterface |
23
|
|
|
{ |
24
|
2 |
|
return $this->check(StringCheckFactory::getNumericCheck(), true); |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
public function empty(): StringRuleInterface |
28
|
|
|
{ |
29
|
2 |
|
return $this->check(StringCheckFactory::getEmptyCheck()); |
30
|
|
|
} |
31
|
|
|
|
32
|
2 |
|
public function notEmpty(): StringRuleInterface |
33
|
|
|
{ |
34
|
2 |
|
return $this->check(StringCheckFactory::getNotEmptyCheck()); |
35
|
|
|
} |
36
|
|
|
|
37
|
2 |
|
public function match(string $regex): StringRuleInterface |
38
|
|
|
{ |
39
|
2 |
|
return $this->check(StringCheckFactory::getMatchCheck($regex)); |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
public function uuid(): StringRuleInterface |
43
|
|
|
{ |
44
|
2 |
|
return $this->check(StringCheckFactory::getUuidCheck()); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
public function hasSubstring(string $substr): StringRuleInterface |
48
|
|
|
{ |
49
|
2 |
|
return $this->check(StringCheckFactory::getHasSubstringCheck($substr)); |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
public function startsWith(string $substr): StringRuleInterface |
53
|
|
|
{ |
54
|
2 |
|
return $this->check(StringCheckFactory::getStartsWithCheck($substr)); |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
public function endsWith(string $substr): StringRuleInterface |
58
|
|
|
{ |
59
|
2 |
|
return $this->check(StringCheckFactory::getEndsWithCheck($substr)); |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
public function lengthIs(IntegerRuleInterface $rule): StringRuleInterface |
63
|
|
|
{ |
64
|
2 |
|
return $this->check(StringCheckFactory::getLengthIsCheck($rule)); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|