
Product
Socket Zero Introduces Automated Remediation PRs
Put vulnerability remediation on autopilot with automated security patches and intelligent dependency upgrades across your GitHub repositories.
since-leoo/hyperf-plugin
Commit history
This tag has pointed to more than one commit over time. Select a commit to view its scan results.
Initial ·
Advanced tools
一个简洁、易用的 Hyperf 插件管理系统,支持插件的完整生命周期管理。
plugin.json 即可创建插件plugin.json 中定义,无需编写 getter 方法composer require since-leoo/hyperf-plugin
# 发布配置文件
php bin/hyperf.php vendor:publish since-leoo/hyperf-plugin
php bin/hyperf.php plugin:make my-plugin
在 bin/hyperf.php 文件中
require BASE_PATH . '/vendor/autoload.php'; 这行代码下 添加以下代码
\SinceLeoo\Plugin\PluginBootstrap::init();
编辑 plugins/my-plugin/plugin.json,设置 enabled: true 启用插件。
php bin/hyperf.php plugin:install vendor/my-plugin
plugins/my-plugin/
├── src/
│ ├── Plugin.php # 插件主类(必需)
│ ├── ConfigProvider.php # 配置提供者(可选)
│ └── Command/ # 命令目录(可选)
├── Database/
│ ├── Migrations/ # 迁移文件(可选,自动检测)
│ └── Seeders/ # 填充器(可选,自动检测)
├── publish/ # 可发布文件(可选)
├── install.lock # 安装状态文件(自动生成)
└── plugin.json # 插件配置(必需)
{
"name": "vendor/my-plugin",
"version": "1.0.0",
"description": "插件描述",
"author": "作者",
"namespace": "Vendor\\MyPlugin",
"priority": 0,
"enabled": true,
"dependencies": ["vendor/other-plugin"],
"composer_require": {
"guzzlehttp/guzzle": "^7.0"
},
"rollback_on_uninstall": false,
"configProvider": "Vendor\\MyPlugin\\ConfigProvider"
}
| 字段 | 必填 | 默认值 | 说明 |
|---|---|---|---|
name | ✅ | - | 插件包名(格式:vendor/name) |
version | ✅ | - | 版本号 |
namespace | ❌ | - | 命名空间(用于自动加载插件类) |
priority | ❌ | 0 | 加载优先级(越大越先加载) |
enabled | ❌ | false | 是否启用插件 |
dependencies | ❌ | [] | 依赖的其他本地插件 |
composer_require | ❌ | {} | 依赖的 Composer 包 |
rollback_on_uninstall | ❌ | false | 卸载时是否回滚迁移 |
configProvider | ❌ | - | ConfigProvider 类名 |
<?php
namespace Vendor\MyPlugin;
use SinceLeoo\Plugin\Contract\AbstractPlugin;
class Plugin extends AbstractPlugin
{
// 安装时调用(迁移和填充之后)
public function install(): void
{
// 发布配置文件等操作
}
// 卸载时调用(回滚迁移之前)
public function uninstall(): void
{
// 清理发布的文件等操作
}
// 每次应用启动时调用(仅 enabled: true 的插件)
public function boot(): void {}
}
所有方法都有空的默认实现,只需覆盖你需要的方法。
plugin.json 必填字段(name, version)composer_require 中声明的第三方包Database/Migrations/ 下的迁移Database/Seeders/ 下的填充器(失败不阻塞)install() 方法install.lock 标记安装完成uninstall() 方法rollback_on_uninstall 配置或 --rollback 选项决定install.lock 文件PluginBootListener 监听 BootApplication 事件enabled: true 的插件priority 降序排列boot() 方法| 命令 | 说明 |
|---|---|
plugin:make [name] | 生成插件骨架 |
plugin:install <name> | 安装插件 |
plugin:uninstall <name> | 卸载插件 |
plugin:list | 查看插件列表 |
plugin:seed <name> | 执行插件填充器 |
# 生成插件(包含迁移、填充器、命令)
php bin/hyperf.php plugin:make my-plugin -m -s -c
# 安装时跳过迁移
php bin/hyperf.php plugin:install vendor/my-plugin --skip-migrations
# 安装时跳过填充器
php bin/hyperf.php plugin:install vendor/my-plugin --skip-seeders
# 卸载时强制回滚迁移
php bin/hyperf.php plugin:uninstall vendor/my-plugin --rollback
# 强制卸载(忽略依赖检查)
php bin/hyperf.php plugin:uninstall vendor/my-plugin --force
# 查看已启用的插件
php bin/hyperf.php plugin:list --status=enabled
# JSON 格式输出
php bin/hyperf.php plugin:list --json
插件的 enabled 状态完全由用户在 plugin.json 中手动设置。设置为 true 后,插件会在应用启动时自动加载。
安装插件时,如果 dependencies 中声明了依赖插件,这些依赖插件必须:
install.lock 文件)plugin.json 中 enabled: true)如果依赖插件未启用,安装会失败并提示用户先启用依赖插件。
publish/ 目录下的文件(如配置文件、视图等)需要在插件的 install() 和 uninstall() 钩子中自行管理:
class Plugin extends AbstractPlugin
{
public function install(): void
{
// 发布配置文件到主项目
$source = __DIR__ . '/../publish/my_plugin.php';
$dest = BASE_PATH . '/config/autoload/my_plugin.php';
if (!file_exists($dest)) {
copy($source, $dest);
}
}
public function uninstall(): void
{
// 清理发布的配置文件
$configFile = BASE_PATH . '/config/autoload/my_plugin.php';
if (file_exists($configFile)) {
unlink($configFile);
}
}
}
composer_require 中声明的包会被安装到主项目的 vendor 目录,并记录到主项目的 composer.json 中。这样 composer update 时不会丢失这些依赖。
卸载插件时,这些依赖不会自动移除。如需移除,请手动执行:
composer remove package/name
插件的迁移文件通过 Hyperf 的 migrate 命令执行,迁移记录存储在 Hyperf 的 migrations 表中,而不是 install.lock 文件。
插件可以通过 ConfigProvider 注册命令、监听器、依赖注入等:
<?php
namespace Vendor\MyPlugin;
class ConfigProvider
{
public function __invoke(): array
{
return [
'commands' => [
Command\MyCommand::class,
],
'listeners' => [
Listener\MyListener::class,
],
'dependencies' => [
Contract\MyInterface::class => Service\MyService::class,
],
];
}
}
| 事件 | 触发时机 |
|---|---|
PluginInstalledEvent | 安装成功后 |
PluginUninstalledEvent | 卸载成功后 |
PluginBootedEvent | 启动后 |
PluginMigratedEvent | 迁移执行后 |
PluginSeededEvent | 填充执行后 |
MIT License
FAQs
一个简洁、易用的 Hyperf 插件管理系统,一键集成项目插件。
We found that since-leoo/hyperf-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.

Product
Put vulnerability remediation on autopilot with automated security patches and intelligent dependency upgrades across your GitHub repositories.

Product
Socket Zero automates vulnerability remediation with upgrades and targeted patches, including fixes for 100% of known, patchable RubyGems CVEs.

Product
Explore Socket’s redesigned Alerts UI, multi-branch repository monitoring, and new tools for resolving findings, searching scans, and filtering security alerts.