patternToRegex($pattern), $filePath); } /** * Check if file path match at least one of patterns. * * @param string $filePath * @param array $patterns * @return bool */ public function executeList(string $filePath, array $patterns): bool { foreach ($patterns as $pattern) { if ($this->execute($filePath, $pattern)) { return true; } } return false; } /** * Convert pattern to regex. * * @param string $pattern * @return string */ public function patternToRegex(string $pattern): string { if (0 === strpos($pattern, 'regex::')) { return str_replace('regex::', '', $pattern); } $mapping = [ '\\\\\\+' => '[+]', '\\\\\\*' => '[*]', '/' => '\/', '\*' => '(?:.*)', '\+' => '(?:.+)', ]; $regex = str_replace( array_keys($mapping), array_values($mapping), preg_quote($pattern, '~') ); return '~^' . $regex . '$~'; } }