This class implements an Ant-like version of PHP's glob() function. The
wildcard "*" matches any number of characters except directory separators.
The double wildcard "**" matches any number of characters, including
directory separators.
Use {@link glob()} to glob the filesystem for paths:
php
foreach (Glob::glob('/project/**.twig') as $path) {
do something...
}
Use {@link match()} to match a file path against a glob:
php
if (Glob::match('/project/views/index.html.twig', '/project/**.twig')) {
path matches
}
You can also filter an array of paths for all paths that match your glob with
{@link filter()}:
php
$filteredPaths = Glob::filter($paths, '/project/**.twig');
Internally, the methods described above convert the glob into a regular
expression that is then matched against the matched paths. If you need to
match many paths against the same glob, you should convert the glob manually
and use {@link preg_match()} to test the paths:
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
}
The method {@link getStaticPrefix()} returns the part of the glob up to the
first wildcard "*". You should always test whether a path has this prefix
before calling the much more expensive {@link preg_match()}.