generated from inherelab/php-pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameValidator.php
55 lines (48 loc) · 1016 Bytes
/
NameValidator.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;
/**
* class NameValidator
*/
class NameValidator extends RegexValidator
{
public const DEFAULT_REGEX = '^\w[\w-]*$';
/**
* @var string
*/
protected string $regex = self::DEFAULT_REGEX;
/**
* @param string $regex
*
* @return static
*/
public static function new(string $regex = self::DEFAULT_REGEX): parent
{
return new self($regex);
}
/**
* Class constructor.
*
* @param string $regex
*/
public function __construct(string $regex = self::DEFAULT_REGEX)
{
parent::__construct($regex);
}
/**
* @param string $regex
*/
public function setRegex(string $regex): void
{
if (!$regex) {
return;
}
parent::setRegex($regex);
}
}