-
Notifications
You must be signed in to change notification settings - Fork 2
/
example2.php
33 lines (27 loc) · 865 Bytes
/
example2.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
<?php
class SimplifiedRegex {
protected $str;
protected $patterns = [];
public function __construct($str) {
$this->str = $str;
}
public function textUppercase($length) {
$pattern = new TextUppercasePattern(); // Assuming TextUppercasePattern implements PatternContract
$pattern->setOptions(new NumberOption(['min' => $length]));
$this->patterns[] = $pattern;
return $this;
}
public function dash() {
$this->patterns[] = new DashPattern(); // Assuming DashPattern implements PatternContract
return $this;
}
// ... other methods ...
public function toRegex() {
$regex = '';
foreach ($this->patterns as $pattern) {
$regex = $pattern->addToPattern($regex);
}
return "/$regex/";
}
// ... check and get methods ...
}