1. Go to this page and download the library: Download lufiipe/simplevent library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lufiipe / simplevent example snippets
use LuFiipe\SimplEvent\Event;
Event::on('DummyEvent', function () {
echo 'The dummy event listener has been triggered! <br>';
});
Event::emit('DummyEvent');
use LuFiipe\SimplEvent\Event;
Event::on('User.Logged', function ($user) {
echo sprintf('%s is authenticated! <br>', $user['name']);
});
Event::emit('User.Logged', ['name' => 'John Doe']);
use LuFiipe\SimplEvent\Event;
Event::on('registered', function ($email, $ip, $device) {
echo sprintf('"%s" registered from address "%s" with a "%s". <br>', $email, $ip, $device);
});
Event::emit('registered', '[email protected]', '127.0.0.1', 'mobile');
use LuFiipe\SimplEvent\Event;
Event::on('User.Registered', function ($user) {
echo 'Log user informations <br>';
});
Event::on('User.Registered', function ($user) {
echo 'Send email to user <br>';
});
Event::emit('User.Registered', $user);
use LuFiipe\SimplEvent\Event;
use LuFiipe\SimplEvent\ListenerPriority;
Event::on('event.name', function () {
echo 'Priority 10 <br>';
}, 10);
Event::on('event.name', function () {
echo 'Priority Max <br>';
}, ListenerPriority::HIGH);
Event::on('event.name', function () {
echo 'Priority 20 <br>';
}, 20);
Event::emit('event.name');
use LuFiipe\SimplEvent\Event;
$listner = Event::on('Comment.post', function ($comment) {
echo sprintf('Comment posted: "%s" <br>', $comment);
});
Event::emit('Comment.post', 'Foo');
$listner->pause();
Event::emit('Comment.post', 'Bar');