1. Go to this page and download the library: Download chipslays/event 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/ */
chipslays / event example snippets
$event->on(..., function () {...}, $sort);
$event->on(..., '\App\Controller@method', $sort);
use Chipslays\Event\Event;
message' => [
'text' => 'hello',
],
'user' => [
'id' => 1234567890,
'firstname' => 'John',
'lastname' => 'Doe'
],
]);
// Callable function
$event->on('message.text', function () {
echo 'This event has `text`';
});
// Class
$event->on('message.text', '\App\SomeController@greeting');
$event->run();
$event->on(['message.text' => 'hello'], function () {
echo 'Hello 👋';
});
$event->on(['*.text' => 'hello'], function () {
echo 'Hello 👋';
});
// At least one "OR Bye OR Goodbye" logic
$event->on([['message.text' => 'Bye'], ['message.text' => 'Goodbye']], function () {
echo 'Bye!';
});
$event->on(['*.text' => 'My name is {name}'], function ($name) {
echo "Nice to meet you, {$name}!";
});
// {user} - is a a optional parameter, it may not be in text
$event->on(['*.text' => '/ban {user} {:time?}'], function ($user = null, $time = null) {
echo "Banned: {$user}, time:" . $time ?? strtotime('+7 day');
});
$event->on('{message}', function ($message) {
echo "Your message: {$message}";
});
$event->on(['*.text' => '/^hello$/i'], function () {
echo "Hello!";
});
// For prevent chain function must return False
$event->on(['*.text' => 'Hi!'], function () {
echo "Hello!";
return false;
});
$event->on(['*.firstname' => 'John'], function () {
echo "This text will never be displayed";
});
// You can use sort for events
$event->on(['*.firstname' => 'John'], function () {
echo "This text will never be displayed";
}, 500);
$event->on(['*.text' => 'Hi!'], function () {
echo "Hello!";
return false;
}, 400);