wip mapper
This commit is contained in:
parent
498a0a0547
commit
058e700f49
@ -4,18 +4,21 @@
|
|||||||
|
|
||||||
use App\Domain\Rule\StringMatchMode;
|
use App\Domain\Rule\StringMatchMode;
|
||||||
|
|
||||||
use function strlen;
|
|
||||||
|
|
||||||
final class StringMatcher
|
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)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return match ($mode) {
|
return match ($mode) {
|
||||||
StringMatchMode::Exact => strcasecmp($input, $pattern) === 0,
|
StringMatchMode::Exact => strcasecmp($input, $pattern) === 0,
|
||||||
StringMatchMode::Contains => stripos($input, $pattern) !== false,
|
StringMatchMode::Contains => str_contains($input, $pattern) ,
|
||||||
StringMatchMode::StartsWith => strncasecmp($input, $pattern, strlen($pattern)) === 0,
|
StringMatchMode::StartsWith => str_starts_with($input, $pattern),
|
||||||
StringMatchMode::EndsWith => str_ends_with(strtolower($input), strtolower($pattern)),
|
StringMatchMode::EndsWith => str_ends_with($input, $pattern),
|
||||||
StringMatchMode::Regex => preg_match($pattern, $input) === 1,
|
StringMatchMode::Regex => preg_match($pattern, $input) === 1,
|
||||||
|
default => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user