Download the PHP package unique/events without Composer
On this page you can find all versions of the php package unique/events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unique/events
More information about unique/events
Files in unique/events
Informations about the package events
Events
This package provides a very basic events system.
Installation
This component requires php >= 7.4. To install it, you can use composer:
Usage
Let's say you want to create a file loader, which will load the file and throw an event with file's content.
In that case you first have to created a simple event object. Let's call it FileLoadEvent
.
Now let's write a simple file loader class:
Now you can use your defined event functionality by adding an event handler:
What this does is it defines an event handler for EVENT_AFTER_LOAD
event. The handler does some logic and marks the event as handled.
If you were to have more than one handler defined for the same event, events would propagate up until all handlers have been called or until one of the handlers sets handled
attribute to true
.
Documentation
on( string $event, $callback )
Sets a new handler for the specified event type.
string $event
- Event name. It is a good idea to define these events as constants on the triggering class.\Closure|array $callback
- Handler of the event. Will receive one parameter:( EventObjectInterface $event )
trigger( string $event_name, EventObjectInterface $event )
Triggers the specified event.
The first assigned handler will be called first. If it does not set EventObjectInterface::setHandled()
the second handler will be called
and so on, until all the handlers have been called or setHandled( true )
has been set.
string $event_name
- Event name. It is a good idea to define these events as constants on the triggering class.EventObjectInterface $event
- Event object
off( string $event, $callback = null )
Removes an event handler from the object. If no handler is provided all handlers will be removed.
string $event
- Event name. It is a good idea to define these events as constants on the triggering class.\Closure|array|null $callback
- Handler of the event that was previously assigned usingon()
.
All versions of events with dependencies
ext-dom Version *