20 lines
664 B
PHP
20 lines
664 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Enums\NameMatchModes;
|
|
|
|
final class InputMatcher
|
|
{
|
|
public static function match(string $input, string $pattern, NameMatchModes $mode): bool
|
|
{
|
|
return match ($mode) {
|
|
NameMatchModes::Exact => strcasecmp($input, $pattern) === 0,
|
|
NameMatchModes::Contains => stripos($input, $pattern) !== false,
|
|
NameMatchModes::StartsWith => strncasecmp($input, $pattern, \strlen($pattern)) === 0,
|
|
NameMatchModes::EndsWith => str_ends_with(strtolower($input), strtolower($pattern)),
|
|
NameMatchModes::Regex => preg_match($pattern, $input) === 1,
|
|
};
|
|
}
|
|
}
|