1 | <?php declare(strict_types=1); |
||
13 | abstract class AbstractCG |
||
14 | { |
||
15 | /** string Character group matching regexp pattern matching group name */ |
||
16 | const PATTERN_GROUP = ''; |
||
17 | |||
18 | /** string Regular expression matching character group */ |
||
19 | const PATTERN_REGEXP = ''; |
||
20 | |||
21 | /** string Character group matching regexp pattern */ |
||
22 | const PATTERN = ''; |
||
23 | |||
24 | /** @var int Character group length */ |
||
25 | protected $length; |
||
26 | |||
27 | /** @var string Character group string */ |
||
28 | protected $string; |
||
29 | |||
30 | /** |
||
31 | * AbstractCharacterGroup constructor. |
||
32 | * |
||
33 | * @param string $string Character group string |
||
34 | * @param int $length Character group length |
||
35 | */ |
||
36 | 56 | public function __construct(string $string, int $length = null) |
|
41 | |||
42 | /** |
||
43 | * Create character group from string string. |
||
44 | * |
||
45 | * @param string $input Input string |
||
46 | * |
||
47 | * @return null|AbstractCG|FixedCG|VariableCG Character group instance |
||
48 | */ |
||
49 | 50 | public static function fromString(string &$input): ?AbstractCG |
|
63 | |||
64 | /** |
||
65 | * Compare character groups. |
||
66 | * |
||
67 | * @param AbstractCG|FixedCG|VariableCG|VariableFixedCG $group Compared character group |
||
68 | * |
||
69 | * @return int -1, 0, 1 Lower, equal, higher |
||
70 | */ |
||
71 | abstract public function compare(AbstractCG $group): int; |
||
72 | |||
73 | /** |
||
74 | * Check if compared character group has same type. |
||
75 | * |
||
76 | * @param AbstractCG $group Compared character group |
||
77 | * |
||
78 | * @return bool True if character group has same type otherwise false |
||
79 | */ |
||
80 | 43 | public function isSameType(AbstractCG $group): bool |
|
84 | |||
85 | /** |
||
86 | * Get two character groups longest common prefix. |
||
87 | * |
||
88 | * @param AbstractCG|FixedCG|VariableCG|VariableFixedCG $group Compared character group |
||
89 | * |
||
90 | * @return string Longest common prefix or empty string |
||
91 | */ |
||
92 | abstract public function getCommonPrefix(AbstractCG $group): string; |
||
93 | |||
94 | /** |
||
95 | * @return string Character group string |
||
96 | */ |
||
97 | 4 | public function getString(): string |
|
101 | |||
102 | /** |
||
103 | * Same character group type comparison. |
||
104 | * |
||
105 | * @param AbstractCG|FixedCG|VariableCG|VariableFixedCG $group Compared character group |
||
106 | * |
||
107 | * @return int -1, 0, 1 Character groups comparison result |
||
108 | */ |
||
109 | abstract protected function compareLength(AbstractCG $group): int; |
||
110 | } |
||
111 |