carloscarucce / php-triggers
Create events and listeners using php
Installs: 1 390
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
README
Create events and listeners using php
Instalation
All you have to do is run composer require carloscarucce/php-triggers or add the following to your composer.json:
{
"require": {
"carloscarucce/php-triggers": "1.*"
}
}
How to use
First you have to setup a listener to your event.
- Declare listener:
use PhpTriggers\Event; use PhpTriggers\EventListener; class MyListener extends EventListener { public function listen(Event $event, ...$data) { list($name, $lastName) = $data; echo "Welcome $name $lastName !"; } public function __construct() { $this->listensTo('check-in'); } }
- Register listener:
$listener = new MyListener(); $listener->register();
Then all you have to do is trigger that event whenever you want to:
use PhpTriggers\Event; Event::create('check-in', [ 'name' => 'John', 'lastName' => 'Doe' ])->trigger();
Enjoy!