Final Class Yiisoft\Yii\Event\ListenerConfigurationChecker
| Inheritance | Yiisoft\Yii\Event\ListenerConfigurationChecker |
|---|
ListenerConfigurationChecker could be used in development mode to check if listeners are defined correctly.
$checker->check($configuration->get('events-web'));
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Event\ListenerConfigurationChecker | |
| check() | Checks the given event configuration and throws an exception in some cases: - incorrect configuration format - incorrect listener format - listener is not a callable - listener is meant to be a method of an object which can't be instantiated | Yiisoft\Yii\Event\ListenerConfigurationChecker |
Method Details
| public mixed __construct ( Yiisoft\Yii\Event\CallableFactory $callableFactory ) | ||
| $callableFactory | Yiisoft\Yii\Event\CallableFactory | |
public function __construct(
private readonly CallableFactory $callableFactory,
) {
}
Checks the given event configuration and throws an exception in some cases: - incorrect configuration format - incorrect listener format - listener is not a callable - listener is meant to be a method of an object which can't be instantiated
| public void check ( array $configuration ) | ||
| $configuration | array |
An array in format of [eventClassName => [listeners]] |
public function check(array $configuration): void
{
foreach ($configuration as $eventName => $listeners) {
if (!is_string($eventName) || !class_exists($eventName)) {
throw new InvalidEventConfigurationFormatException(
'Incorrect event listener format. Format with event name must be used. Got ' .
var_export($eventName, true) . '.'
);
}
if (!is_iterable($listeners)) {
$type = get_debug_type($listeners);
throw new InvalidEventConfigurationFormatException(
"Event listeners for $eventName must be an iterable, $type given."
);
}
foreach ($listeners as $listener) {
try {
if (!$this->isCallable($listener)) {
throw new InvalidListenerConfigurationException(
$this->createNotCallableMessage($listener)
);
}
} catch (ContainerExceptionInterface $exception) {
throw new InvalidListenerConfigurationException(
'Could not instantiate event listener or listener class has invalid configuration. Got ' .
$this->listenerDump($listener) . '.',
0,
$exception
);
}
}
}
}
Signup or Login in order to comment.