Constants This class defines the following constants:

FilesystemUtils::GLOB_ROOTFIRST
FilesystemUtils::GLOB_CHILDFIRST

Methods This class defines the following methods:

static glob (string $pattern, int $flags) -> array|bool

Extended glob() functionality that supports double star ** (globstar) wildcard.

PHP's glob() implementation doesn't allow for ** wildcard. In Bash 4 it can be enabled with globstar setting.

In case the ** wildcard is not used in the pattern then this method just calls PHP's glob().

For full documentation see PHP's glob() documentation.

It's worth noting that if you want to find files inside current directory and their subdirectories, then you have to use a GLOB_BRACE flag and pattern, e.g.:

echo \MD\Foundation\Utils\FilesystemUtils::glob('{,** /}*.js', GLOB_BRACE); // note: remove space between * and /
// -> array(
//      'main.js',
//      'dir/script.js',
//      'dir/more/scripts.js'
// );

Implementation of this convention varies between libs in various languages and MD\Foundation sticks with what Bash manual states. More about this is explained in #2.

Additionally it provides sorting option to the results, which you can pass along with other flags. Constants FilesystemUtils::GLOB_ROOTFIRST and FilesystemUtils::GLOB_CHILDFIRST sort the results either as "root first" where files in a directory are listed before directories and subdirectories, or "child first" where subdirectories are listed before files.

Arguments:
string $pattern

The pattern. Supports ** wildcard.

int $flags

[optional] glob() flags. See glob()'s documentation. Default: 0.

Returns:
array|bool