1 | <?php |
||
18 | class Alias implements ValidatorInterface |
||
19 | { |
||
20 | /** |
||
21 | * pattern for alias |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | |||
26 | protected $_pattern = '^[a-zA-Z0-9-]{3,100}$'; |
||
27 | |||
28 | /** |
||
29 | * array of system alias |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | |||
34 | protected $_systemArray = |
||
35 | [ |
||
36 | 'admin', |
||
37 | 'login', |
||
38 | 'recover', |
||
39 | 'reset', |
||
40 | 'logout', |
||
41 | 'register', |
||
42 | 'module', |
||
43 | 'search' |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * get the pattern |
||
48 | * |
||
49 | * @since 4.3.0 |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | |||
54 | 1 | public function getPattern() : string |
|
55 | { |
||
56 | 1 | return $this->_pattern; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * validate the alias |
||
61 | * |
||
62 | * @since 4.3.0 |
||
63 | * |
||
64 | * @param string $alias alias to be validated |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | |||
69 | 12 | public function validate(string $alias = null) : bool |
|
70 | { |
||
71 | 12 | return preg_match('/' . $this->_pattern . '/', $alias); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * match system alias |
||
76 | * |
||
77 | * @since 4.3.0 |
||
78 | * |
||
79 | * @param string $alias alias to be matched |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | |||
84 | 3 | public function matchSystem(string $alias = null) : bool |
|
88 | } |
||
89 |