# Glob

> 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.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Manifest](/docs/extensions/scaffold/reference/manifest/index.md) › Glob

| final class | `PHPForge\Scaffold\Manifest\Glob` |
| --- | --- |
| Source | [`src/Manifest/Glob.php`](https://github.com/php-forge/scaffold/blob/main/src/Manifest/Glob.php#L26) |

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.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`lookup()`](#method-lookup) static | Returns the value of the first key of `$map` that matches `$path`; an exact key wins over globs, which match in declaration order. | `Glob` |
| [`matches()`](#method-matches) static | Returns whether `$pattern` matches the whole of `$path`. | `Glob` |
| [`matchesAny()`](#method-matchesAny) static | Returns whether any of `$patterns` matches the whole of `$path`. | `Glob` |
| [`prunes()`](#method-prunes) static | Returns whether a `<dir>/**` pattern of `$patterns` excludes every descendant of `$directory`, so a walk can skip it. | `Glob` |
| [`toRegex()`](#method-toRegex) static | Converts a glob pattern into an anchored PCRE regex, for example `#^config/[^/]*\.php$#` for `config/*.php`. | `Glob` |

## Method details

### lookup() <span id="method-lookup"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$map` | `array<array-key, PHPForge\Scaffold\Manifest\TValue>` | Values keyed by glob pattern; integer-like patterns are integer keys. |
| `$path` | `string` | Relative path with forward slashes. |

**Returns**

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

### matches() <span id="method-matches"></span>

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

Returns whether `$pattern` matches the whole of `$path`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Glob pattern to match against. |
| `$path` | `string` | Relative path with forward slashes; this method does not convert backslashes. |

**Returns**

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

### matchesAny() <span id="method-matchesAny"></span>

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

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$patterns` | `list<string>` | Glob patterns. |
| `$path` | `string` | Relative path with forward slashes. |

**Returns**

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

### prunes() <span id="method-prunes"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$patterns` | `list<string>` | Glob patterns. |
| `$directory` | `string` | Relative directory path with forward slashes. |

**Returns**

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

### toRegex() <span id="method-toRegex"></span>

```php
public static function toRegex(string $pattern): string
```

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pattern` | `string` | Glob pattern to convert. |

**Returns**

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