# CollectorRegistrar

> Resolves the configured debug collectors and validates their stable IDs before request capture.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › [service](/docs/extensions/debug/reference/service/index.md) › CollectorRegistrar

| class | `yii\debug\service\CollectorRegistrar` |
| --- | --- |
| Source | [`src/service/CollectorRegistrar.php`](https://github.com/yii2-extensions/debug/blob/main/src/service/CollectorRegistrar.php#L29) |

Resolves the configured debug collectors and validates their stable IDs before request capture.

Built-in collectors are omitted when their optional package is unavailable. Explicit application configuration
remains authoritative and may still register a custom collector under the same ID.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-module"></span>`$module` protected readonly constructor | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module owning the collectors and read for configuration at call time. | `CollectorRegistrar` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Binds collector registration to the debug module. | `CollectorRegistrar` |
| [`register()`](#method-register) | Instantiates every configured collector, instruments it, and returns the coordinator driving the capture. | `CollectorRegistrar` |

## Method details

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

```php
public function __construct(yii\debug\Module $module)
```

Binds collector registration to the debug module.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$module` | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module owning the collectors and read for configuration at call time. |

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

```php
public function register(array<string, array<string, mixed>|string> $core, array<array-key, array<string, mixed>|Closure(PHPForge\Debug\Capture\CapturePolicy): mixed|PHPForge\Debug\CollectorInterface|string> $configured): PHPForge\Debug\Collector\CollectorCoordinator
```

Instantiates every configured collector, instruments it, and returns the coordinator driving the capture.

An array entry declaring `enabled` as `false` is skipped before its class is resolved, so an uninstalled
optional package is not an error. A `Closure` entry receives the module [`CapturePolicy`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Capture/CapturePolicy.php), built once per
call, so a provider collector redacts with the rules the Request panel applies.

Every [`Module::$dispatchers`](/docs/extensions/debug/reference/module/index.md#property-dispatchers) key must name a registered or a disabled collector, so a mistyped entry fails
here instead of leaving its panel silently empty.

Each resolved collector is instrumented right away through [`Collector::instrument()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-instrument): the panels are built
afterwards and a panel constructor may already hit the framework, so instrumentation installed only at
[`Application::EVENT_BEFORE_REQUEST`](/docs/api/yii/base/application/index.md#event-EVENT_BEFORE_REQUEST) would miss the debugger's own bootstrap work.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$core` | `array<string, array<string, mixed>\|string>` | Built-in collector definitions indexed by collector ID. |
| `$configured` | `array<array-key, array<string, mixed>\|`[`Closure`](https://www.php.net/manual/en/class.closure.php)`(`[`CapturePolicy`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Capture/CapturePolicy.php)`): mixed\|`[`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php)`\|string>` | Collector definitions declared by the application; a `Closure` result is validated at call time. |

**Returns**

`PHPForge\Debug\Collector\CollectorCoordinator`: Coordinator holding the registered collectors in resolution order.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when a collector configuration, a collector ID, a dispatcher entry, or the resolved set is invalid.