Event
in package
Class \Hoa\Event\Event.
Events are asynchronous at registration, anonymous at use (until we receive a bucket) and useful to largely spread data through components without any known connection between them.
Tags
Table of Contents
Constants
- KEY_EVENT = 0
- Event ID key.
- KEY_SOURCE = 1
- Source object key.
Properties
- $_callable : array<string|int, mixed>
- Callables, i.e. observer objects.
- $_register : array<string|int, mixed>
- Static register of all observable objects, i.e. \Hoa\Event\Source object, i.e. object that can send event.
Methods
- attach() : Event
- Attach an object to an event.
- detach() : Event
- Detach an object to an event.
- eventExists() : bool
- Check whether an event exists.
- getEvent() : Event
- Manage multiton of events, with the principle of asynchronous attachments.
- isListened() : bool
- Check if at least one callable is attached to an event.
- notify() : void
- Notify, i.e. send data to observers.
- register() : void
- Declare a new object in the observable collection.
- unregister() : void
- Undeclare an object in the observable collection.
- __construct() : mixed
- Privatize the constructor.
Constants
KEY_EVENT
Event ID key.
public
mixed
KEY_EVENT
= 0
Tags
KEY_SOURCE
Source object key.
public
mixed
KEY_SOURCE
= 1
Tags
Properties
$_callable
Callables, i.e. observer objects.
protected
array<string|int, mixed>
$_callable
= []
$_register
Static register of all observable objects, i.e. \Hoa\Event\Source object, i.e. object that can send event.
private
static array<string|int, mixed>
$_register
= []
Methods
attach()
Attach an object to an event.
public
attach(mixed $callable) : Event
It can be a callable or an accepted callable form (please, see the \Hoa\Consistency\Xcallable class).
Parameters
- $callable : mixed
-
Callable.
Return values
Eventdetach()
Detach an object to an event.
public
detach(mixed $callable) : Event
Please see $this->attach() method.
Parameters
- $callable : mixed
-
Callable.
Return values
EventeventExists()
Check whether an event exists.
public
static eventExists(string $eventId) : bool
Parameters
- $eventId : string
-
Event ID.
Return values
boolgetEvent()
Manage multiton of events, with the principle of asynchronous attachments.
public
static getEvent(string $eventId) : Event
Parameters
- $eventId : string
-
Event ID.
Return values
EventisListened()
Check if at least one callable is attached to an event.
public
isListened() : bool
Return values
boolnotify()
Notify, i.e. send data to observers.
public
static notify(string $eventId, Source $source, Bucket $data) : void
Parameters
Tags
register()
Declare a new object in the observable collection.
public
static register(string $eventId, Source|string $source) : void
Note: Hoa's libraries use hoa://Event/AnID for their observable objects;
Parameters
- $eventId : string
-
Event ID.
- $source : Source|string
-
Observable object or class.
Tags
unregister()
Undeclare an object in the observable collection.
public
static unregister(string $eventId[, bool $hard = false ]) : void
Parameters
- $eventId : string
-
Event ID.
- $hard : bool = false
-
If false, just delete the source, else, delete source and attached callables.
__construct()
Privatize the constructor.
private
__construct() : mixed