# ProjectRootFinder

> Finds the project root by walking up from a directory to the nearest one that contains the Composer manifest.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Config](/docs/extensions/scaffold/reference/config/index.md) › ProjectRootFinder

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

Finds the project root by walking up from a directory to the nearest one that contains the Composer manifest.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`find()`](#method-find) static | Returns the nearest directory, starting at `$directory` and walking up, that contains the Composer manifest named by [`VendorDirResolver::manifestName()`](/docs/extensions/scaffold/reference/config/vendordirresolver/index.md#method-manifestName). | `ProjectRootFinder` |

## Method details

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

```php
public static function find(string $directory): string|null
```

Returns the nearest directory, starting at `$directory` and walking up, that contains the Composer manifest
named by [`VendorDirResolver::manifestName()`](/docs/extensions/scaffold/reference/config/vendordirresolver/index.md#method-manifestName).

An absolute manifest path is not searched for: its directory is the project root, as for the Composer plugin.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$directory` | `string` | Absolute path of the directory where the search starts. |

**Returns**

`string|null`: Absolute path of the project root, or `null` when the filesystem root is reached first or the absolute manifest does not exist.