PHP code example of baagee / php-event

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

    

baagee / php-event example snippets

 

// 匿名函数 不传参数
// 重复事件
\BaAGee\Event\Event::listen('event1', function () {
    echo 'event1' . PHP_EOL;
    return 'return event1';
});
// 第三个参数为true 一次性事件 触发后就删除,下次就不会再次触发了 
\BaAGee\Event\Event::listen('event1', function () {
    echo 'once event1' . PHP_EOL;
    return 'return once event1';
}, true);
// 触发event1事件
$res = \BaAGee\Event\Event::trigger('event1');
var_dump($res);
$res = \BaAGee\Event\Event::trigger('event1');
var_dump($res);

event1
once event1
/Users/baagee/PhpstormProjects/github/php-event/tests/test1.php:23:
array(2) {
  [0] =>
  string(13) "return event1"
  [1] =>
  string(18) "return once event1"
}
event1
/Users/baagee/PhpstormProjects/github/php-event/tests/test1.php:25:
array(1) {
  [0] =>
  string(13) "return event1"
}