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

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

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

blueselene/hooks

最新稳定版本:1.0

Composer 安装命令:

composer require blueselene/hooks

包简介

A very simple hook library inspired by MediaWiki's (somewhat)

README 文档

README

A very simple and easy to use hooks library. You register your hooks, register your hook handlers, and go.

Written mostly for fun (and to have something that is easy to write PHPUnit tests for). MPL-2.0 licensed.

Requires at least PHP 8.3 (because that's the version I use and test with), but otherwise has no dependencies of its own.

Usage

An example is probably best here.

<?php

require 'vendor/autoload.php';

interface Foo {

	public function echo(string $world): void;
}

class Bar implements Foo {

	#[\Override]
	public function echo(string $world): void {
		echo 'Hello ' . $world . PHP_EOL;
	}
}

$hooks = new \BlueSelene\Hooks\Hooks();

/**
 * Name of the handler, what class should handlers extend or implement, method name, number of parameters
 */
$hooks->registerNewHook('test', Foo::class, 'echo', 1);


$hooks->registerHookHandler('test', new Bar());

/**
 * Name of the handler, followed by an arbitrary number of parameters, as long as they meet the number defined in Hooks::registerNewHook()
 * $result contains an array with the return values of all the handlers, in the order in which they were called (which happens to also be the order in which they are registered, from first to last)
 */
$result = $hooks->fireHook('test', 'world');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2026-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固