English
1 month ago
Esperanto
1 month ago
French
1 month ago
Italian
1 month ago
NorwegianBokmal
1 month ago
Portuguese
1 month ago
Spanish
1 month ago
Turkish
1 month ago
Pattern.php
1 month ago
Patterns.php
1 month ago
Ruleset.php
1 month ago
Substitution.php
1 month ago
Substitutions.php
1 month ago
Transformation.php
1 month ago
Transformations.php
1 month ago
Word.php
1 month ago
Pattern.php
36 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWPSCOPED\Doctrine\Inflector\Rules; |
| 5 | |
| 6 | use function preg_match; |
| 7 | /** @internal */ |
| 8 | final class Pattern |
| 9 | { |
| 10 | /** @var string */ |
| 11 | private $pattern; |
| 12 | /** @var string */ |
| 13 | private $regex; |
| 14 | public function __construct(string $pattern) |
| 15 | { |
| 16 | $this->pattern = $pattern; |
| 17 | if (isset($this->pattern[0]) && $this->pattern[0] === '/') { |
| 18 | $this->regex = $this->pattern; |
| 19 | } else { |
| 20 | $this->regex = '/' . $this->pattern . '/i'; |
| 21 | } |
| 22 | } |
| 23 | public function getPattern() : string |
| 24 | { |
| 25 | return $this->pattern; |
| 26 | } |
| 27 | public function getRegex() : string |
| 28 | { |
| 29 | return $this->regex; |
| 30 | } |
| 31 | public function matches(string $word) : bool |
| 32 | { |
| 33 | return preg_match($this->getRegex(), $word) === 1; |
| 34 | } |
| 35 | } |
| 36 |