This commit is contained in:
Dr Masroor Ehsan 2025-01-22 10:57:03 +06:00
parent 058e700f49
commit 9777669f84

View File

@ -8,10 +8,15 @@ final class StringMatcher
{ {
public static function match(string $input, string $pattern, StringMatchMode $mode): bool public static function match(string $input, string $pattern, StringMatchMode $mode): bool
{ {
if (empty($input) || empty($pattern)) { if (blank($input) || blank($pattern)) {
return false; return false;
} }
if ($mode !== StringMatchMode::Regex) {
$input = strtolower($input);
$pattern = strtolower($pattern);
}
return match ($mode) { return match ($mode) {
StringMatchMode::Exact => strcasecmp($input, $pattern) === 0, StringMatchMode::Exact => strcasecmp($input, $pattern) === 0,
StringMatchMode::Contains => str_contains($input, $pattern) , StringMatchMode::Contains => str_contains($input, $pattern) ,