The new TEventHandler attaches specific data to a managed event handler. This is used by wrapping your Event Handler calllable with new TEventHandler(..., $data) and specify your $data. The handler will then receive the $data as a 3rd parameter after $sender and $param.
here is an example of its being used:
$handler = new TEventHandler([$object, 'myHandler'], ['key' => 'data']);
$handler($sender, $param); // <- invokable
$component->attachEventHandler('onMyEvent', $handler, $priority);
// In the $object class when $component::onMyEvent is raised:
public function myHandler(object $sender, mixed $param, mixed $data = null): mixed
{
// $data === ['key' => 'data']
// ....
}
Callable handler objects are converted to WeakReference. The exception are Closure and IWeakRetainable as they may be the only instance in the application. TEventHandler implements IWeakRetainable.
TEventHandler, TWeakList and TWeakCallableCollection do not convert IWeakRetainable to WeakReference. (nor Closure)
TWeakList and TWeakCallableCollection manage the weak callable handler object inside the TEventHandler rather than the TEventHandler itself.
TWeakList and TWeakCallableCollection have indexOf that will allow searching of TEventHandler by their callable regardless of the data. This is also true for TWeakCallableCollection::priorityOf. This is the same behavior as Yii2 Prado allows for searching of specific callables with specific data (being unique) as well, unlike Yii2.
TEventHandler, TWeakList and TWeakCallable handle nested TEventHandler properly.
undocumented $name (of event) after event handler parameter $sender and $param removed.
-IEventParameter is used by raiseEvent to capture the Event Name in the event parameter. TEventParameter captures the name of the event being raised as standard.
-TBroadcastEventParameter is regressed for new event name capturing of TEventParameter
TEventContent is regressed to pass the event name as a parameter rather than rely upon undocumented features.
lots of Unit tests
Yii2 has had data associated with event handlers for a bit, but their implementation is just hacking their base component with an extra variable. In this implementation, The TEventHandler is an object rather than just embedded with the handler. The TEventHandler can be passed around, it's data changed dynamically after the event handler is attached.
This also allows for TEventHandler Nesting where the data (if its an array) of nested TEventHandlers can combine. The chlldren take precedence over the parents, similar to PHP class structure.
The new TEventHandler attaches specific data to a managed event handler. This is used by wrapping your Event Handler calllable with
new TEventHandler(..., $data)
and specify your $data. The handler will then receive the $data as a 3rd parameter after $sender and $param.here is an example of its being used:
Callable handler objects are converted to WeakReference. The exception are Closure and IWeakRetainable as they may be the only instance in the application. TEventHandler implements IWeakRetainable.
Yii2 has had data associated with event handlers for a bit, but their implementation is just hacking their base component with an extra variable. In this implementation, The TEventHandler is an object rather than just embedded with the handler. The TEventHandler can be passed around, it's data changed dynamically after the event handler is attached.
This also allows for TEventHandler Nesting where the data (if its an array) of nested TEventHandlers can combine. The chlldren take precedence over the parents, similar to PHP class structure.