InList
This commit is contained in:
parent
41d53d1cc5
commit
8ba341e6cf
@ -8,6 +8,6 @@ enum MatchMode: string
|
||||
case Contains = 'CONTAINS';
|
||||
case StartsWith = 'STARTS_WITH';
|
||||
case EndsWith = 'ENDS_WITH';
|
||||
case InArray = 'IN_ARRAY';
|
||||
case InList = 'IN_LIST';
|
||||
case Regex = 'REGEX';
|
||||
}
|
||||
|
@ -6,22 +6,32 @@
|
||||
|
||||
final class ContentMatcher
|
||||
{
|
||||
private static function matchList(string $input, string $pattern): bool
|
||||
{
|
||||
$patterns = collect(explode(',', $pattern))
|
||||
->map(fn ($s) => trim($s))
|
||||
->filter(fn ($s) => filled($s));
|
||||
foreach ($patterns as $search) {
|
||||
if (self::match($input, $search, MatchMode::Exact)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function match(string $input, string $pattern, MatchMode $mode): bool
|
||||
{
|
||||
if (blank($input) || blank($pattern)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($mode !== MatchMode::Regex) {
|
||||
$input = strtolower($input);
|
||||
$pattern = strtolower($pattern);
|
||||
}
|
||||
|
||||
return match ($mode) {
|
||||
MatchMode::Exact => strcasecmp($input, $pattern) === 0,
|
||||
MatchMode::Contains => str_contains($input, $pattern) ,
|
||||
MatchMode::StartsWith => str_starts_with($input, $pattern),
|
||||
MatchMode::EndsWith => str_ends_with($input, $pattern),
|
||||
MatchMode::InList => self::matchList($input, $pattern),
|
||||
MatchMode::Regex => preg_match($pattern, $input) === 1,
|
||||
};
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public function run(): void
|
||||
'dicom_tag' => DicomTagIdentifiers::Modality->value,
|
||||
'search_pattern' => 'MR,CT',
|
||||
'dicom_routing_rule_id' => $rul_chev_mr->id,
|
||||
'match_mode' => MatchMode::InArray->value,
|
||||
'match_mode' => MatchMode::InList->value,
|
||||
'case_sensitive' => true,
|
||||
]);
|
||||
|
||||
@ -110,7 +110,7 @@ public function run(): void
|
||||
'dicom_tag' => DicomTagIdentifiers::Modality->value,
|
||||
'search_pattern' => 'CR,DX',
|
||||
'dicom_routing_rule_id' => $rul_chev_xr->id,
|
||||
'match_mode' => MatchMode::InArray->value,
|
||||
'match_mode' => MatchMode::InList->value,
|
||||
'case_sensitive' => true,
|
||||
]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user