Skip to content
PHP Ecosystem
Explore

DispatcherAttacher

API reference › Debug › service › DispatcherAttacher

classyii\debug\service\DispatcherAttacher
Sourcesrc/service/DispatcherAttacher.php

Hands every collector named in Module::$dispatchers to the application component the application pairs it with, so the component emits its PSR-14 events into the collector.

The way the component takes the collector is detected, never declared: a public eventDispatcher property (or a Yii getter/setter pair) wins, then a constructor parameter named eventDispatcher. A definition is amended without instantiating the component; an instantiated component only accepts the property form. A dispatcher the component already configures is kept, so a populated application dispatcher is never replaced by the collector.

PropertyTypeDescriptionDefined by
$module protected readonly constructoryii\debug\ModuleDebug module owning the dispatcher map and the collector coordinator, read at call time.DispatcherAttacher
MethodDescriptionDefined by
__construct()Binds dispatcher attachment to the module’s collectors and component map.DispatcherAttacher
attach()Attaches every configured collector to its application component.DispatcherAttacher
dispatcherArgumentKey() protectedReturns the __construct() key a component definition takes its dispatcher under.DispatcherAttacher
public function __construct(yii\debug\Module $module)

Binds dispatcher attachment to the module’s collectors and component map.

Parameters

ParameterTypeDescription
$moduleyii\debug\ModuleDebug module owning the dispatcher map and the collector coordinator, read at call time.
public function attach(yii\base\Application $app): void

Attaches every configured collector to its application component.

Runs once every bootstrap class had its turn, so a component a bootstrap class registers is seen. A collector disabled through enabled => false is skipped; CollectorRegistrar already rejected an entry naming no configured collector.

Parameters

ParameterTypeDescription
$appyii\base\ApplicationApplication owning the components.

Throws

  • yii\base\InvalidConfigException: when a collector is not a PSR-14 dispatcher, or when its component is unknown, instantiated without a writable eventDispatcher property, or unable to take the collector.
protected function dispatcherArgumentKey(class-string $class, array<array-key, mixed> $arguments): int|string|null

Returns the __construct() key a component definition takes its dispatcher under.

A definition indexing its arguments by position gets the dispatcher at the position its constructor declares, because Yii rejects a definition mixing named and positional arguments; every other definition gets it by name.

Override point: a subclass returning its own key attaches the collector to a component whose constructor names the dispatcher parameter differently.

Parameters

ParameterTypeDescription
$classclass-stringComponent class whose constructor is inspected.
$argumentsarray<array-key, mixed>Arguments the definition already declares.

Returns

int|string|null: Key to write the dispatcher under, or null when the constructor declares no eventDispatcher parameter.