initphp/events

事件(钩子)库

1.0.2 2022-07-09 08:54 UTC

This package is auto-updated.

Last update: 2024-09-09 13:29:34 UTC


README

它允许你在软件的不同地方运行外部函数。它允许你在WordPress生态系统内设置一个类似的结构,称为钩子。

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

需求

安装

composer require initphp/events

用法

在将事件添加的地方调用 trigger() 方法。通过 on() 方法发送事件。

require_once "vendor/autoload.php";
use \InitPHP\Events\Events;

Events::on('helloTrigger', function(){
    echo 'Hello World' . PHP_EOL;
}, 100);

Events::on('helloTrigger', function(){
    echo 'Hi, World' . PHP_EOL;
}, 99);

Events::trigger('helloTrigger');

输出

Hi World
Hello World

参数使用

require_once "vendor/autoload.php";
use \InitPHP\Events\Events;

Events::on('helloTrigger', function($name, $myName){
    echo 'Hello ' . $name . '. I am ' . $myName . '.' . PHP_EOL;
}, 100);

Events::on('helloTrigger', function($name, $myName){
    echo 'Hi ' . $name . '. I am ' . $myName . '.' . PHP_EOL;
}, 99);

Events::trigger('helloTrigger', 'World', 'John');

输出

Hi World. I am John.
Hello World. I am John.

致谢

许可

版权所有 © 2022 MIT 许可证