mozartk / simple-event
Simple events.
v0.1.0
2018-05-24 13:20 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ^3.7|~4|~5|~6
This package is auto-updated.
Last update: 2025-01-10 05:20:12 UTC
README
This is a simple PHP event implementation.Installation
composer require mozartk/simple-event
Basic Usage
How to run
<?php include "vendor/autoload.php"; use \mozartk\SimpleEvent\SimpleEvent; $event = new SimpleEvent(); $event->set("event1", function(){ return "Hello World"; }); $result = $event->emit("testEvent"); echo $result; //return Hello World
If you want to run only once...
$event->one("event2", function(){ return 111; }); $result = $event->emit("testEvent"); echo $result; //return 1 $result = $event->emit("testEvent"); //Exceptions on this line.
..And set specific limits...
$event->setWithCount("testEvent", function(){ return 1; }, 3); $result = $event->emit("testEvent"); $result = $event->emit("testEvent"); $result = $event->emit("testEvent"); $result = $event->emit("testEvent"); //Exceptions on this line.
License
Made by mozartk.
The MIT License (MIT). Please see License File for more information.