# DebugEventDispatcher

> Records PSR-14 event and immediate caller metadata before delegating to the application dispatcher.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Event](/docs/extensions/yii3-debug/reference/event/index.md) › DebugEventDispatcher

| final readonly class | `Yii3\Debug\Event\DebugEventDispatcher` |
| --- | --- |
| Implements | `Psr\EventDispatcher\EventDispatcherInterface` |
| Source | [`src/Event/DebugEventDispatcher.php`](https://github.com/yii3/debug/blob/main/src/Event/DebugEventDispatcher.php#L19) |

Records PSR-14 event and immediate caller metadata before delegating to the application dispatcher.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates an event-dispatcher proxy that records each event before delegation. | `DebugEventDispatcher` |
| [`dispatch()`](#method-dispatch) | Records the event and its immediate caller, then delegates to the application dispatcher. | `DebugEventDispatcher` |

## Method details

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

```php
public function __construct(Psr\EventDispatcher\EventDispatcherInterface $dispatcher, Yii3\Debug\Collector\EventCollector $collector, PHPForge\Debug\Instrumentation\InstrumentationGuard|null $guard = null)
```

Creates an event-dispatcher proxy that records each event before delegation.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$dispatcher` | `Psr\EventDispatcher\EventDispatcherInterface` | Application dispatcher every event is delegated to. |
| `$collector` | [`Yii3\Debug\Collector\EventCollector`](/docs/extensions/yii3-debug/reference/collector/eventcollector/index.md) | Collector recording the event and its immediate caller. |
| `$guard` | `PHPForge\Debug\Instrumentation\InstrumentationGuard\|null` | Guard isolating capture failures, or `null` to build the default. |

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

```php
public function dispatch(object $event): object
```

Records the event and its immediate caller, then delegates to the application dispatcher.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$event` | `object` | Event being dispatched. |

**Returns**

`object`: Event as returned by the application dispatcher.