Event
Event class and methods
This library is abandoned. Please consider using a different library.
Opis\Events\Event
is the standard event class provided by Opis Events.
Creating events
To create a new event you have to create an instance of Opis\Events\Event
.
use Opis\Events\Event;
// Cancellable event
$event1 = new Event("event.name.1", true);
// Non-cancellable event
$event2 = new Event("event.name.2", false);
If an event is not cancellable, the stop method will have no effect when called.
When a event is cancelled, other listeners will not be invoked.
Please note that NOT all events should be cancellable.
In order to fire (dispatch) the event, you have to pass it to the dispatch method of the event dispatcher
You can also fire a new basic event using emit, in this case the emit method itself will create and dispatch a standard event object.
Methods
name
Returns the name of the event.
signature
public function name(): string
usage
if ($event->name() === 'system.init') {
// ...
}
cancelled
Checks if the event was cancelled using the stop method.
signature
public function cancelled(): bool
usage
if ($event->cancelled()) {
// ...
}
stop
Cancels the propagation of the event, if the event is cancellable.
signature
public function stop(): void
usage
$event->stop();