lkt/hooks
最新稳定版本:1.0.0
Composer 安装命令:
composer require lkt/hooks
包简介
LKT Hooks engine
README 文档
README
Installation
composer require lkt/hooks
Register hooks
use Lkt\Hooks\Hook; Hook::register('hook-name', 'hook-action', [callable])
For example:
use Lkt\Hooks\Hook; Hook::register('create-user', 'mail-set-up-password', [callable]) Hook::register('create-user', 'mail-admin-new-user-created', [callable])
Every action can be registered as many times as you need. All results will be returned when triggered.
The only limitation it's all action handler must have the same method definition.
For example:
class HookStack { public static function mailPassword(int $userId, string $name, string $lastname): bool { // ... your stuff return true; } // If we want to define another method with different code, // the method must have the same arguments and return type. // This is a valid method: public static function mailPassword2(int $userId, string $name, string $lastname): bool { // ... another stuff return true; } // This is an invalid method: public static function mailPassword3(int $userId, string $name): bool { // ... third stuff return true; } } use Lkt\Hooks\Hook; Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword']) Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword2']) Hook::register('create-user', 'mail-set-up-password', [HookStack::class, 'mailPassword3'])
Trigger a hook
use Lkt\Hooks\Hook; Hook::run('hook-name', ...$args)
For example:
use Lkt\Hooks\Hook; $id = 1; $name = 'John'; $lastname = 'Doe'; $response = Hook::register('create-user', $id, $name, $lastname);
The previous example will return a HookResponse object containing the result of all triggers called.
统计信息
- 总下载量: 126
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-11