1 | <?php |
||
29 | abstract class AbstractStringCheck implements ICheck { |
||
30 | |||
31 | /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */ |
||
32 | protected $matches; |
||
33 | |||
34 | /** @var IL10N */ |
||
35 | protected $l; |
||
36 | |||
37 | /** |
||
38 | * @param IL10N $l |
||
39 | */ |
||
40 | public function __construct(IL10N $l) { |
||
43 | |||
44 | /** |
||
45 | * @param IStorage $storage |
||
46 | * @param string $path |
||
47 | */ |
||
48 | public function setFileInfo(IStorage $storage, $path) { |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | abstract protected function getActualValue(); |
||
56 | |||
57 | /** |
||
58 | * @param string $operator |
||
59 | * @param string $value |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function executeCheck($operator, $value) { |
||
66 | |||
67 | /** |
||
68 | * @param string $operator |
||
69 | * @param string $checkValue |
||
70 | * @param string $actualValue |
||
71 | * @return bool |
||
72 | */ |
||
73 | protected function executeStringCheck($operator, $checkValue, $actualValue) { |
||
87 | |||
88 | /** |
||
89 | * @param string $operator |
||
90 | * @param string $value |
||
91 | * @throws \UnexpectedValueException |
||
92 | */ |
||
93 | public function validateCheck($operator, $value) { |
||
94 | if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) { |
||
95 | throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
||
96 | } |
||
97 | |||
98 | if (in_array($operator, ['matches', '!matches']) && |
||
99 | @preg_match($value, null) === false) { |
||
100 | throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param string $pattern |
||
106 | * @param string $subject |
||
107 | * @return int|bool |
||
108 | */ |
||
109 | protected function match($pattern, $subject) { |
||
121 | } |
||
122 |