/glob

A PHP implementation of Git's glob.

Primary LanguagePHPMIT LicenseMIT

Webmozart Glob

Build Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads Dependency Status

Latest release: none

A utility implementing Git-like globbing. Wildcards in the glob match any number of characters (zero or more), including directory separators.

The main class of the package is Glob. Use Glob::glob() to glob the filesystem:

use Webmozart\Glob\Glob;

$paths = Glob::glob('/path/to/dir/*.css'); 

You can also use GlobIterator to search the filesystem iteratively. However, the iterator is not guaranteed to return sorted results:

use Webmozart\Glob\Iterator\GlobIterator;

$iterator = new GlobIterator('/path/to/dir/*.css');

foreach ($iterator as $path) {
    // ...
}

The package also provides utility methods for comparing paths against globs. Use Glob::match() to match a path against a glob:

if (Glob::match($path, '/path/to/dir/*.css')) {
    // ...
}

Glob::filter() filters a list of paths by a glob:

$paths = Glob::filter($paths, '/path/to/dir/*.css');

The same can be achieved iteratively with GlobFilterIterator:

use Webmozart\Glob\Iterator\GlobFilterIterator;

$iterator = new GlobFilterIterator('/path/to/dir/*.css', new ArrayIterator($paths));

foreach ($iterator as $path) {
    // ...
}

Authors

Installation

Use Composer to install the package:

$ composer require webmozart/glob@dev

Contribute

Contributions to the package are always welcome!

Support

If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter.

License

All contents of this package are licensed under the MIT license.