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
Patterns.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWPSCOPED\Doctrine\Inflector\Rules; |
| 5 | |
| 6 | use function array_map; |
| 7 | use function implode; |
| 8 | use function preg_match; |
| 9 | /** @internal */ |
| 10 | class Patterns |
| 11 | { |
| 12 | /** @var string */ |
| 13 | private $regex; |
| 14 | public function __construct(Pattern ...$patterns) |
| 15 | { |
| 16 | $patterns = array_map(static function (Pattern $pattern) : string { |
| 17 | return $pattern->getPattern(); |
| 18 | }, $patterns); |
| 19 | $this->regex = '/^(?:' . implode('|', $patterns) . ')$/i'; |
| 20 | } |
| 21 | public function matches(string $word) : bool |
| 22 | { |
| 23 | return preg_match($this->regex, $word, $regs) === 1; |
| 24 | } |
| 25 | } |
| 26 |