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