PHP code example of mozartk / simple-event

1. Go to this page and download the library: Download mozartk/simple-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/ */

    

mozartk / simple-event example snippets




mozartk\SimpleEvent\SimpleEvent;

$event = new SimpleEvent();
$event->set("event1", function(){
     return "Hello World";
});

$result = $event->emit("testEvent");

echo $result; //return Hello World

$event->one("event2", function(){
    return 111;
});
$result = $event->emit("testEvent");
echo $result; //return 1
$result = $event->emit("testEvent"); //Exceptions on this line.

$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.