nickjbedford/hooks
Composer 安装命令:
composer require nickjbedford/hooks
包简介
Hooks is a small library that provided hookable actions and filters, similar to WordPress. This can be used in any PHP 8.0+ project.
README 文档
README
Hooks is a small library that provided hookable actions and filters, similar to WordPress. This can be used in any PHP 7.4+ project and is a simple way of implementing plugin capabilities in your applications by exposing hookable actions and filters to plugin-code.
The Hook class provides a simple interface to registering functions
to call under specific hook names, sorted by priority. A hook's list
of functions can then be executed with optional parameters, or used
as an accumulator for an initial value.
While the Hook class itself can be used to create, register and
execute hooks, you can also use the global hook_* functions to
shortcut these operations.
Menu Example
A menu might include a default list of items, then this list may be passed to a filter hook to allow plugins to modify or append to the list.
Application Usage
$menu = [ 'Plugins' => [ new MenuItem('Plugin Manager', '/plugins/index') ] ]; $menuItems = hook_filter('main_menu', $menu); // Add menu items to UI...
Plugin Usage
A plugin can then modify the list by receiving it and adding its own items through a callback added to the same hook.
hook_add('main_menu', function(array $menu) { $menu['Plugins'][] = new MenuItem('My Plugin', '/my-plugin/'); return $menu; });
Executing Actions with Hooks
To create, add a function to a hook then execute it, use the following alternatives:
$hook = \YetAnother\Hook::get('do_stuff'); $hook->add(function($param) { print($param); }); $hook->run('Hello, world!'); // "Hello, world!" is printed
hook_add('do_stuff', fn($param) => print($param)); hook_run('do_stuff', 'Hello, world!');
Filtering with Hooks
By registering callbacks on a hook used as a filter, you can receive input and pass results to the next function in the filter.
hook_add('accumulate', fn($initial, $parameter) => $initial + $parameter); hook_add('accumulate', fn($initial, $parameter) => $initial * $parameter); $result = hook_filter('accumulate', 5, 7); // $result = 54 ((5 + 7) * 7)
hook_add('menu', function(array $menu) { $menu[] = 'World'; return $menu; }); $menu = hook_filter('menu', [ 'Hello' ]); // $menu = [ 'Hello', 'World' ]
nickjbedford/hooks 适用场景与选型建议
nickjbedford/hooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filters」 「hooks」 「actions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nickjbedford/hooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nickjbedford/hooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nickjbedford/hooks 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.
Simple filters for laravel
Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
Hooks integrated in Voyager
Turns CPD style XML reports into Github pull-request annotations via the Checks API. This script is meant for use within your Github Action.
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-04