Download the PHP package riven/hyperf-callee without Composer
On this page you can find all versions of the php package riven/hyperf-callee. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package hyperf-callee
Callee 库使用文档
简介
Callee 是一个基于 Hyperf 框架的事件调用管理库,用于简化事件驱动的代码组织和调用。它提供了一种优雅的方式来注册和调用事件处理方法,支持注解方式和直接代码方式注册。
功能
- 通过方法注解、反射机制实现轻量级事件回调「将
#[Callee(枚举)]绑定到任意方法进行回调」 - 功能支持:
- 发布订阅
- 优先级
- 协程异步
- 事务后执行
安装
要通过 Composer 安装此包,请运行以下命令:
使用
配置
Callee\ConfigProvider::class服务提供者应该会自动注册。如果未自动注册,在你的 Hyperf 应用程序中启用 Callee,你需要在 config/autoload/dependencies.php 文件中注册它:
1. 定义事件枚举
首先,你需要定义事件枚举,实现 CalleeEvent 接口:
2. 注册事件处理方法
方式 1:使用注解注册
方式 2:直接代码注册
3. 调用事件处理方法
高级使用
作用域管理
你可以为事件处理方法指定作用域,以便在不同的上下文环境中使用不同的处理方法:
优先级管理
你可以为事件处理方法设置优先级,以便控制多个处理方法的执行顺序:
事务支持
你可以使用 afterCommit 参数来指定事件处理方法在事务提交后执行:
API 参考
注解参数
event: 事件枚举或事件数组,用于触发该方法的调用scope: 作用域,可选参数,用于限制该注解的作用范围priority: 优先级,用于决定多个 Callee 在同一事件中被调用的顺序afterCommit: 是否在事务成功提交后才执行该方法async: 是否异步执行该方法
函数
call(CalleeEvent|array|null $event, array $args = [], bool $strict = false, mixed $default = null, ?string $scope = null): mixed: 调用事件处理方法
收集器方法
CalleeCollector::addCallee(array $callable, Callee $callee): void: 添加被调用方法到容器CalleeCollector::hasCallee(CalleeEvent|array|null $event, ?string $scope = null): bool: 检查是否存在对应的调用方法CalleeCollector::getCallee(CalleeEvent|array|null $event, ?string $scope = null): ?SplPriorityQueue: 获取调用方法及参数映射CalleeCollector::clear(?string $key = null): void: 清除容器数据
完整代码示例
注意事项
- 确保在使用
call()函数之前,已经设置了 Hyperf 的应用容器 - 对于异步事件处理方法,需要确保 Hyperf 的任务队列组件已正确配置
- 对于事务支持,需要确保在事务环境中使用
afterCommit参数 - 优先级值越大,执行顺序越靠前
贡献
我们非常欢迎任何形式的贡献!如果你发现了问题或者有改进的想法,请先查看我们的 贡献指南。对于新功能的提案或错误修复,请直接提交 Pull Request。
- Issues: https://github.com/woweijun123/callee/issues
- Pull Requests: https://github.com/woweijun123/callee/pulls
All versions of hyperf-callee with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.3
hyperf/context Version ~3.1
hyperf/database Version ~3.1.0
hyperf/db-connection Version ~3.1.0
hyperf/di Version ~3.1
hyperf/event Version ~3.1
hyperf/framework Version ~3.1.0
hyperf/logger Version ~3.1.0
hyperf/context Version ~3.1
hyperf/database Version ~3.1.0
hyperf/db-connection Version ~3.1.0
hyperf/di Version ~3.1
hyperf/event Version ~3.1
hyperf/framework Version ~3.1.0
hyperf/logger Version ~3.1.0
The package riven/hyperf-callee contains the following files
Loading the files please wait ...