baagee / php-event
PHP event library
v0.0.1
2019-03-25 07:14 UTC
Requires
- php: >=7.1
This package is auto-updated.
Last update: 2024-12-27 15:41:08 UTC
README
PHP Event Library
php事件定义与触发
安装
composer require baagee/php-event
使用示例:
include_once __DIR__ . '/../vendor/autoload.php'; // 匿名函数 不传参数 // 重复事件 \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"
}