Download the PHP package ikkez/f3-events without Composer
On this page you can find all versions of the php package ikkez/f3-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ikkez/f3-events
More information about ikkez/f3-events
Files in ikkez/f3-events
Package f3-events
Short Description Sweet event system for the PHP Fat-Free Framework
License GPL-3.0
Homepage https://github.com/ikkez/f3-events
Informations about the package f3-events
Sugar Events
This is a event system for the PHP Fat-free Framework. Here is what's included so far:
- emit events from any point of your app
- attach one or multiple listeners to an event
- a listener (hook) can have a priority order
- additional options for listeners
- local events on specific objects
- send payload and context data with an event
- sub-events and event propagation
- stop the event chain
- works with F3 v3.5 and PHP v7.2+
This event system is experimental, so please handle with care.
Installation
-
Method 1: use composer:
composer require ikkez/f3-events
- Method 2: copy the
lib/event.php
file into your F3lib/
directory or another directory that is known to the AUTOLOADER
How does it work:
The Event class is a child of Prefab, so you can get it everywhere like this:
Define a listener / hook:
Send an event:
Send payload with event:
Multiple listeners with prioritization:
Stop the event chain:
Additional event context data:
Additional listener options:
I think that are the basic usage samples that could fit the most cases. Nevertheless here are some more advanced things you can do:
Filter payload:
Add a sub-event. These are called after the parent event. Listeners and sub-events follow the FIFO processing, which means the first that is registered is the first that will be called.
Remove hooks:
There is also a mechanic build in which supports local events for mappers and such, which have implemented it:
Unit tests
to add the tests to your local F3 test-bench, add this:
License
You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.
Copyright (C) 2017 Christian Knuth [ikkez]