Skip to content
PHP Ecosystem
Explore

Glob

API reference › Scaffold › Manifest › Glob

final classPHPForge\Scaffold\Manifest\Glob
Sourcesrc/Manifest/Glob.php

Matches forward-slash paths against manifest glob patterns: * and ? within one path segment, ** across segments, single-level {a,b} alternatives, and byte-exact literals for everything else.

MethodDescriptionDefined by
lookup() staticReturns the value of the first key of $map that matches $path; an exact key wins over globs, which match in declaration order.Glob
matches() staticReturns whether $pattern matches the whole of $path.Glob
matchesAny() staticReturns whether any of $patterns matches the whole of $path.Glob
prunes() staticReturns whether a <dir>/** pattern of $patterns excludes every descendant of $directory, so a walk can skip it.Glob
toRegex() staticConverts a glob pattern into an anchored PCRE regex, for example #^config/[^/]*\.php$# for config/*.php.Glob
public static function lookup(array<array-key, PHPForge\Scaffold\Manifest\TValue> $map, string $path): PHPForge\Scaffold\Manifest\TValue|null

Returns the value of the first key of $map that matches $path; an exact key wins over globs, which match in declaration order.

Parameters

ParameterTypeDescription
$maparray<array-key, PHPForge\Scaffold\Manifest\TValue>Values keyed by glob pattern; integer-like patterns are integer keys.
$pathstringRelative path with forward slashes.

Returns

PHPForge\Scaffold\Manifest\TValue|null: Value of the matching pattern, or null when no pattern matches.

public static function matches(string $pattern, string $path): bool

Returns whether $pattern matches the whole of $path.

Parameters

ParameterTypeDescription
$patternstringGlob pattern to match against.
$pathstringRelative path with forward slashes; this method does not convert backslashes.

Returns

bool: true when the pattern matches the full path, false otherwise.

public static function matchesAny(list<string> $patterns, string $path): bool

Returns whether any of $patterns matches the whole of $path.

Parameters

ParameterTypeDescription
$patternslist<string>Glob patterns.
$pathstringRelative path with forward slashes.

Returns

bool: true when at least one pattern matches the path, false otherwise.

public static function prunes(list<string> $patterns, string $directory): bool

Returns whether a <dir>/** pattern of $patterns excludes every descendant of $directory, so a walk can skip it.

Parameters

ParameterTypeDescription
$patternslist<string>Glob patterns.
$directorystringRelative directory path with forward slashes.

Returns

bool: true when $patterns holds <directory>/**, false otherwise.

public static function toRegex(string $pattern): string

Converts a glob pattern into an anchored PCRE regex, for example #^config/[^/]*\.php$# for config/*.php.

Parameters

ParameterTypeDescription
$patternstringGlob pattern to convert.

Returns

string: PCRE regex with the # delimiter, anchored to match the full string.