# EventCollector

> Captures PSR-14 event metadata for the current request.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Collector](/docs/extensions/yii3-debug/reference/collector/index.md) › EventCollector

| final class | `Yii3\Debug\Collector\EventCollector` |
| --- | --- |
| Implements | [`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php) |
| Source | [`src/Collector/EventCollector.php`](https://github.com/yii3/debug/blob/main/src/Collector/EventCollector.php#L32) |

Captures PSR-14 event metadata for the current request.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-captureContext"></span>`$captureContext` | `bool` | Opt-in capture of whitelisted lifecycle context. Arbitrary event properties remain unread. Default: `false`. | `EventCollector` |
| <span id="property-traceLimit"></span>`$traceLimit` | `int` | Opt-in argument-free trace depth; zero disables capture, and sixteen is the hard maximum. Default: `0`. | `EventCollector` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`capture()`](#method-capture) | Encodes the captured events into the Events panel payload. | `EventCollector` |
| [`id()`](#method-id) | Returns the stable identifier of this collector. | `EventCollector` |
| [`record()`](#method-record) | Records only dispatch metadata while collection is active. | `EventCollector` |
| [`shutdown()`](#method-shutdown) | Stops capturing and clears the events accumulated for the request. | `EventCollector` |
| [`startup()`](#method-startup) | Starts capturing and resets the nesting and scope counters. | `EventCollector` |

## Method details

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

```php
public function capture(): array<string, mixed>|null
```

Encodes the captured events into the Events panel payload.

**Returns**

`array<string, mixed>|null`: Encoded Events panel payload; `null` when the collector never started.

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

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

Returns the stable identifier of this collector.

**Returns**

`string`: Stable ID pairing this collector with its panel.

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

```php
public function record(object $event, string $senderClass = ''): void
```

Records only dispatch metadata while collection is active.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$event` | `object` | Event being dispatched. |
| `$senderClass` | `string` | Immediate class that invoked the decorated dispatcher, used as a fallback source. |

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

```php
public function shutdown(): void
```

Stops capturing and clears the events accumulated for the request.

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

```php
public function startup(): void
```

Starts capturing and resets the nesting and scope counters.