Use this method if you need to match many paths against a glob:
php
$staticPrefix = Glob::getStaticPrefix('/project/**.twig');
$regEx = Glob::toRegEx('/project/**.twig');
if (0 !== strpos($path, $staticPrefix)) {
no match
}
if (!preg_match($regEx, $path)) {
no match
}
You should always test whether a path contains the static prefix of the
glob returned by {@link getStaticPrefix()} to reduce the number of calls
to the expensive {@link preg_match()}.
public static toRegEx ( string $glob, integer $flags, $delimiter = '~' ) : string | ||
$glob | string | The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. |
$flags | integer | A bitwise combination of the flag constants in this class. |
return | string | The regular expression for matching the glob. |