gburtini/hooks 问题修复 & 功能扩展

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

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

gburtini/hooks

Composer 安装命令:

composer require gburtini/hooks

包简介

Hooks, plugins, filters, event-driven programming, plugin architecture all in a clean easy interface.

README 文档

README

Event-driven programming, a plugin architecture, hooks, filters, all wrapped in to a simple, efficient and clean Composer-ready interface.

This is an elegant way of coding plugin architectures or other decoupled software solutions. The class provides three major methods: bind, run and filter; combined, these allow you to integrate in to existing systems without interfering with their existing code.

There's also a plugin loader in Plugins.php which can be used to load a directory of optional code. Use is simple: Plugins::load("directory") will traverse the directory and load all non-disabled (~, . prefix) folders containing a init.php file.

Installation

Everything you need is contained within the single file Hooks.php, but the most convenient way to install is with composer:

composer require gburtini/hooks

Usage

  • bind(string $hook, callback $callback, int $priority) - binds a callback to a hook
  • run(string $hook, array $parameters) - executes all the functions bound to a given hook
  • filter(string $hook, object $value, array $parameters) - executes all the functions bound to a given hook, passing in $value each time, and finally return the value

The designed use case is that throughout your existing software, you will call Hooks::filter and Hooks::run where you want to allow users to hook with a specified $hook value. Then users can call Hooks::bind() anytime before your code runs to associate code with the various locations -- filters will return the value (so that a function can change it) and run calls will simply run functions with no in-code side effects.

Debugging

The Hooks class has a debug level setting which produces some output indicating which hooks are running and when. Call Hooks::setDebugLevel($debug_level) at runtime to set the debug output. $debug_level can take on the following values:

  • Hooks::DEBUG_NONE - the default, no debug output.
  • Hooks::DEBUG_EVENTS - a list of the ::run and ::filter calls as they happen.
  • Hooks::DEBUG_CALLS - a list of every callback executed in each hoo/filter.
  • Hooks::DEBUG_BINDS - a list of each time a bind is setup for a hook or filter.
  • Hooks::DEBUG_INTERACTION - outputs every call to a class method (bind, run, filter, and the private methods)
  • Hooks::DEBUG_ALL - all of the above combined.

You can also combine these with the bitwise OR, for example Hooks::DEBUG_EVENTS | Hooks::DEBUG_BINDS outputs all the run/filter/bind calls as they happen.

Future Work

A nice future feature would be to enforce some sort of constraints on what these binds can do -- allowing "untrusted" (in the sense of the data) code to run in some sort of quasi-sandbox; for example, the filters could check to ensure the value was constrained to a particular type, range or callback validation.

Timing functionality for the debug code to see which hooks and associated callbacks are slow is an interesting angle here too.

Sorting can be called less frequently. If nothing has changed, it is unnecessary to call the sort function again. That said, the used quicksort variant should be rapid on already sorted data.

License

Copyright (C) 2012-2015 Giuseppe Burtini

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

gburtini/hooks 适用场景与选型建议

gburtini/hooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176 次下载、GitHub Stars 达 15, 最近一次更新时间为 2015 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「event」 「plugins」 「plugin」 「events」 「filter」 「HOOK」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gburtini/hooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gburtini/hooks 我们能提供哪些服务?
定制开发 / 二次开发

基于 gburtini/hooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 15
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL
  • 更新时间: 2015-03-31