nabeghe / file-hooker
基于文件的钩子系统。
1.0.0
2024-02-15 03:50 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-15 05:08:09 UTC
README
这是一个简单的基于文件的钩子系统。这意味着每个回调都位于一个PHP文件中。
🫡 使用
🚀 安装
您可以通过composer安装此包
composer require nabeghe/file-hooker
📁 钩子目录
为您的钩子创建一个目录。
该目录中每个PHP文件(无后缀.php)的名称将是您的钩子名称。也允许使用子目录。
每个文件返回一个回调。这个回调接收两个参数,data和angler。data是发送到回调的项目。在过滤器中,它必须是一个数组,但在操作中可以是任何内容。过滤器中data的索引0是过滤的内容。但在回调中,必须返回整个数组。
示例
<?php use Nabeghe\FileHooker\FileHooker; // This is a custom object called angler. It is sent as the second argument to the callbacks. $angler = new stdClass(); $angler = new FileHooker($angler); // Add a new path where the hooks are located. $hooker->add(__DIR__.'/hooks'); // Action $hooker->action('print', ['text' => 'Hi']); // Filter $result = $hooker->filter('remove_spaces', ['Hadi Akbarzadeh']); echo $result;
在钩子目录中创建一个名为print.php
的文件
<?php return function ($data, $angler) { echo $data['text']; };
在钩子目录中创建一个名为remove_spaces.php
的文件
<?php return function ($data, $angler) { $data = str_replace(' ', '', $data[0]); return $data; };
📖 许可证
版权所有(c)2024 Hadi Akbarzadeh
MIT许可证下授权,详细信息请参阅LICENSE.md