Skip to content

Getting Started

Globby is a PHP library for file pattern matching using glob patterns, similar to how shells match files.

Terminal window
composer require cline/globby
use Cline\Globby\Globby;
// Find all PHP files
$files = Globby::find('**/*.php');
// Find files in specific directory
$files = Globby::find('src/**/*.php');
// Find multiple patterns
$files = Globby::find(['**/*.php', '**/*.js']);
PatternDescription
*Match any characters except /
**Match any characters including /
?Match single character
[abc]Match characters in brackets
[!abc]Match characters not in brackets
{a,b}Match any of the patterns
// All PHP files recursively
Globby::find('**/*.php');
// PHP files in src only (not subdirs)
Globby::find('src/*.php');
// Test files
Globby::find('tests/**/*Test.php');
// Config files (json or yaml)
Globby::find('config/*.{json,yaml}');
// All files except vendor
Globby::find('**/*', exclude: ['vendor/**']);