纳贝格/挂钩

基于 Symfony EventDispatcher 的简单挂钩系统库(动作和过滤器)。

0.2.0 2024-09-19 18:03 UTC

This package is auto-updated.

Last update: 2024-09-19 18:12:01 UTC


README

基于 Symfony EventDispatcher 的简单挂钩系统库(动作和过滤器)。

🫡 使用方法

🚀 安装

您可以通过 composer 安装此包。

composer require nabeghe/hooker

示例

请查看存储库中的示例文件夹。

动作

require 'vendor/autoload.php';

use Nabeghe\Hooker\Hooker;
use Nabeghe\Hooker\Action;

$hooker = new Hooker();

$hooker->setDefaultArgToHooks('protocol', 'https://');

$hooker->listen('your_custom_action_name', function (Action $action) {
    echo $action['protocol'].$action['url'].PHP_EOL;
}, 2);

$hooker->action('your_custom_action_name', ['url' => 'https://github.com/nabeghe/hooker']);

过滤器

require 'vendor/autoload.php';

use Nabeghe\Hooker\Hooker;
use Nabeghe\Hooker\Filter;

$hooker = new Hooker();

$hooker->listen('your_custom_action_name', function (Filter $filter) {
    if ($filter->getValue() === null) {
        $filter->setValue(8 + $filter['default']);
    }
});

$value = $hooker->filter('your_custom_action_name', null, ['default' => 5]);
echo $value; // 13