# RequestCollector

> Captures the HTTP request and response state for the Request panel.

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

| class | `yii\debug\collectors\RequestCollector` |
| --- | --- |
| Extends | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| Implements | [`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php) |
| Source | [`src/collectors/RequestCollector.php`](https://github.com/yii2-extensions/debug/blob/main/src/collectors/RequestCollector.php#L23) |

Captures the HTTP request and response state for the Request panel.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-censoredVariableNames"></span>`$censoredVariableNames` | `array<int, string>` | Variable names whose values should be replaced with `$censorString` in the captured snapshot. Default: `[]`. | `RequestCollector` |
| <span id="property-censorString"></span>`$censorString` | `string` | Replacement value emitted for variables listed in [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames). Default: `'****'`. | `RequestCollector` |
| [`$displayVars`](#property-displayVars) | `array<int, string>` | PHP predefined variables that the collector may surface. Default: `['_COOKIE', '_FILES', '_GET', '_POST', '_SERVER', '_SESSION']`. | `RequestCollector` |
| <span id="property-module"></span>[`$module`](/docs/extensions/debug/reference/collectors/collector/index.md#property-module) | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md)`\|null` | Debug module supplying the log target and sibling collectors, assigned by the module on registration. Default: `null`. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-capture"></span>[`capture()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-capture) final | Encodes the typed snapshot built by the subclass into the payload persisted for the panel. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`id()`](#method-id) | Returns the stable ID pairing this collector with the Request panel. | `RequestCollector` |
| <span id="method-instrument"></span>[`instrument()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-instrument) | Installs low-level instrumentation as soon as the module registers the collector, before the panels are built. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-shutdown"></span>[`shutdown()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-shutdown) final | Deactivates the collector once, releasing any subscription created by [`start()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-start). | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-startup"></span>[`startup()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-startup) final | Activates the collector once at the start of the request lifecycle. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`censorArray()`](#method-censorArray) protected | Replaces the values of any [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames) entries with [`$censorString`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censorString), returning the sanitized top-level data. | `RequestCollector` |
| [`getFlashes()`](#method-getFlashes) protected | Returns the active flash messages without deleting them or touching the deletion counters. | `RequestCollector` |
| <span id="method-getLogMessages"></span>[`getLogMessages()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-getLogMessages) protected | Returns the accumulated log messages, optionally filtered by level, category, and exclusion lists. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-getLogTarget"></span>[`getLogTarget()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-getLogTarget) protected | Returns the initialized log target of the owning debug module. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-isStarted"></span>[`isStarted()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-isStarted) protected | Returns whether the collector is active for the current request. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`normalizeResponseHeaders()`](#method-normalizeResponseHeaders) protected | Aggregates a raw response-header list into a name → value map, merging duplicates into arrays and masking entries whose name appears in [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames). | `RequestCollector` |
| [`snapshot()`](#method-snapshot) protected | Snapshots the request/response state: action, route, headers, body, status code, flash messages, and the configured superglobals. | `RequestCollector` |
| <span id="method-start"></span>[`start()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-start) protected | Hook invoked once when the collector activates; subclasses subscribe to framework events here. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-stop"></span>[`stop()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-stop) protected | Hook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |

## Property details

### $displayVars <span id="property-displayVars"></span>

```php
public array<int, string> $displayVars = ['_COOKIE', '_FILES', '_GET', '_POST', '_SERVER', '_SESSION']
```

PHP predefined variables that the collector may surface.

Each variable must be accessible via `$GLOBALS`; otherwise it is silently skipped.

## Method details

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

```php
public function id(): string
```

Returns the stable ID pairing this collector with the Request panel.

**Returns**

`string`: Stable collector ID.

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

```php
protected function censorArray(array<string, mixed> $data): array<string, mixed>
```

Replaces the values of any [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames) entries with [`$censorString`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censorString), returning the
sanitized top-level data.

Also masks `requestBody.Raw` whenever a `requestBody.*` key is censored, so the verbatim payload does not leak
the censored field by accident.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `array<string, mixed>` | Captured request payload. |

**Returns**

`array<string, mixed>`: Sanitized payload with masked values.

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

```php
protected function getFlashes(): array<int|string, mixed>
```

Returns the active flash messages without deleting them or touching the deletion counters.

**Returns**

`array<int|string, mixed>`: Flash messages keyed by their session flash name.

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

```php
protected function normalizeResponseHeaders(array<int, string> $rawHeaders): array<int|string, array<int, string>|string>
```

Aggregates a raw response-header list into a name → value map, merging duplicates into arrays and masking entries
whose name appears in [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rawHeaders` | `array<int, string>` | Header lines in `Name: value` form, as returned by `headers_list()`; bare strings without a colon are kept verbatim at int-keyed slots. |

**Returns**

`array<int|string, array<int, string>|string>`: Aggregated header map with masked values.

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

```php
protected function snapshot(): PHPForge\Debug\Panel\Request\RequestSnapshot|null
```

Snapshots the request/response state: action, route, headers, body, status code, flash messages, and the
configured superglobals.

Header names listed in [`$censoredVariableNames`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censoredVariableNames) are emitted with [`$censorString`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#property-censorString) instead of their real
value; the same masking is applied to top-level keys in the captured payload via [`censorArray()`](/docs/extensions/debug/reference/collectors/requestcollector/index.md#method-censorArray).

**Returns**

`PHPForge\Debug\Panel\Request\RequestSnapshot|null`: Captured request payload; `null` when the collector never started.