jessegall/php-hooks
最新稳定版本:v0.1.0
Composer 安装命令:
composer require jessegall/php-hooks
包简介
README 文档
README
A simple package that makes it easy to hook traits to any class.
Installation
composer require jessegall/php-hooks
Usage
To enable hooks in your class, you will need to use the HasHooks trait and add it to your class:
use JesseGall\Hooks\HasHooks; class MyClass { use HasHooks; }
You can then define hook methods in your traits by adding methods with a specific naming convention. The method name
should be prefixed with hook, followed by the name of the trait. For example:
trait MyTrait { public function hookMyTrait() { // Will be called when the hook is initialized } }
Of course, you'll also need to add the trait to your class:
use JesseGall\Hooks\HasHooks; use MyTrait; class MyClass { use HasHooks, MyTrait; }
To initialize the hooks, you can call the initializeHooks method on an instance of your class:
$myClass = new MyClass(); $myClass->initializeHooks();
Customizing Hooks
By default, the hook methods are expected to be prefixed with hook. You can change this prefix by defining a hookPrefix
property in your class:
use JesseGall\Hooks\HasHooks; class MyClass { use HasHooks, MyTrait; protected $hookPrefix = 'myHook'; }
With the above configuration, the hook methods in your traits should be prefixed with myHook instead of hook. For example:
trait MyTrait { public function myHookMyTrait() { // This method will be called when the hook is initialized } }
统计信息
- 总下载量: 147
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-26