nabeghe/file-hooker 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nabeghe/file-hooker

最新稳定版本:v1.1.0

Composer 安装命令:

composer require nabeghe/file-hooker

包简介

Hooking system based on files.

README 文档

README

A simple Hooking System based on files. This means that each callback is located in a PHP file.

🫡 Usage

🚀 Installation

You can install the package via composer:

composer require nabeghe/file-hooker

📁 Hooks Directory

Create a directory for your hooks.

The name of each php file in this directory without suffix (.php) will be the name of your hook. Subdirectories are also allowed.

Each file returns a callback. This callback receives two arguments, data and angler. Data is the items sent to the callback. In filters, it must be an array, but in actions, it can be anything. Index 0 of data in filters is what is filtered. But in callbacks, the array itself must be returned.

Example

<?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();
$hooker = 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;

Create a file named print.php in the hooks directory:

<?php

return function ($data, $angler) {
    echo $data['text'];
};

Create a file named remove_spaces.php in the hooks directory:

<?php

return function ($data, $angler) {
    $data = str_replace(' ', '', $data[0]);
    return $data;
};

📖 License

Licensed under the MIT license, see LICENSE.md for details.

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-15