Sledgehammer Framework

EventEmitter

EventEmitter.

Example subclass: class Button { use EventEmitter; protected $events = array( 'click' => [] ); // optional method that gets executed when the 'click' event is fired. protected function onClick($sender) } }

$button = new Button(); $button->on('click', function ($sender) { echo 'clicked'; });

// Or property style event-binding: (Only 1 listeners per event)

$button->onClick = function () { echo 'clicked'; };

// reset all listeners. $this->onClick = null;

Table of Contents

$__kvo  : array<string|int, mixed>
Storage array for the properties with KVO (Key Value Observer) listeners.
__get()  : mixed
Getting a non-existing or KVO property.
__set()  : mixed
Setting a non-existing or KVO property.
hasEvent()  : bool
Check id the $event is a registered event.
off()  : mixed
Remove a callback from an event.
on()  : string
Add a callback for an event.
trigger()  : mixed
Trigger an event.

Properties

$__kvo

Storage array for the properties with KVO (Key Value Observer) listeners.

private array<string|int, mixed> $__kvo = []

Methods

__get()

Getting a non-existing or KVO property.

public __get(string $property) : mixed
Parameters
$property : string
Return values
mixed

__set()

Setting a non-existing or KVO property.

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Return values
mixed

hasEvent()

Check id the $event is a registered event.

public hasEvent(string $event) : bool
Parameters
$event : string
Return values
bool

off()

Remove a callback from an event.

public off(string $event, string $identifier) : mixed
Parameters
$event : string
$identifier : string
Return values
mixed

on()

Add a callback for an event.

public on(string $event, Closure|string|array<string|int, mixed> $callback) : string
Parameters
$event : string
$callback : Closure|string|array<string|int, mixed>
Return values
string

identifier

trigger()

Trigger an event.

public trigger(string $event, stdClass $sender[, mixed $args = null ]) : mixed
Parameters
$event : string
$sender : stdClass
$args : mixed = null

(optional)

Return values
mixed

Search results