Skip to content

Commit

Permalink
Replaced regex with fnmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
bayram-aloware committed Feb 24, 2022
1 parent ab11e09 commit 3837669
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions src/WildcardMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle(array $wildcards = []): array
if (count($queues) > 0) {
foreach ($queues as $queue) {
foreach ($wildcards as $wildcard) {
if ($this->wildcardMatches($wildcard, $queue)) {
if (fnmatch($wildcard, $queue)) {
$matched[] = $queue;
}
}
Expand All @@ -39,24 +39,4 @@ public function handle(array $wildcards = []): array

return $matched;
}

/**
* Match queues with given wildcard
*
* @param string $pattern
* @param string $haystack
* @return bool
*/
protected function wildcardMatches($pattern, $haystack): bool
{
$regex = str_replace(
["\*"], // wildcard chars
['.*', '.'], // regexp chars
preg_quote($pattern)
);

preg_match('/^' . $regex . '$/is', $haystack, $matches);

return count($matches) > 0;
}
}

0 comments on commit 3837669

Please sign in to comment.