Download the PHP package wuguofeng/webman-bouncer without Composer
On this page you can find all versions of the php package wuguofeng/webman-bouncer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wuguofeng/webman-bouncer
More information about wuguofeng/webman-bouncer
Files in wuguofeng/webman-bouncer
Package webman-bouncer
Short Description Bouncer RBAC (roles & abilities) plugin for webman. Adapts silber/bouncer to webman's long-running process model with per-request state isolation.
License MIT
Informations about the package webman-bouncer
wuguofeng/webman-bouncer
Silber\Bouncer(RBAC 角色与能力)的 webman 插件。 将 bouncer 适配到 webman 的长驻进程模型:每个请求独立的 Bouncer 实例(独立的剪贴板与缓存), 避免进程级静态状态串号与权限缓存过期问题。
特性
- 100% 复用
silber/bouncer原版 API:Bouncer::allow()/assign()/is()/can()/forbid()、模型 trait$user->can()/$user->isAn()。 - 每请求重建实例(
request缓存策略,ArrayStore),改权限即刻生效,无需手动refresh()。 - 多租户 scope 支持:
scope_resolver每请求重置,防止租户串号。 - 自动初始化 Illuminate 容器 + Eloquent(优先复用
webman/database的连接池)。 - 支持 MySQL / PostgreSQL;提供
php webman bouncer:install按驱动方言一键建表。
安装
安装后插件配置自动拷贝到 config/plugin/wuguofeng/webman-bouncer/。
配置
编辑 config/plugin/wuguofeng/webman-bouncer/app.php:
缓存策略(cache)
| 值 | 说明 |
|---|---|
'request'(默认) |
每请求独立内存缓存(ArrayStore),改动即刻生效,无需手动刷新。推荐日常使用 |
'none' |
完全禁用缓存,每次校验都查库 |
store 名(如 'file'、'redis') |
跨请求/跨进程持久缓存,复用你项目的 config/cache.php(webman/cache)里的 store |
使用跨请求缓存前先安装并配置 webman/cache:
跨请求缓存适合权限数据量大、校验频繁、变更低频的场景(首次校验少查库、后续全部命中缓存)。 代价是权限改动不即时生效,变更后需要手动失效:
用户模型:
建表:
使用
中间件
config/plugin/wuguofeng/webman-bouncer/middleware.php 默认注册了 BouncerMiddleware(作用于所有请求),
保证请求处理器执行前已存在新鲜的 Bouncer 实例(trait 用法依赖它)。不需要可移除。
命令
| 命令 | 说明 |
|---|---|
php webman bouncer:install |
创建 bouncer 四张表(abilities / roles / assigned_roles / permissions)。按 config/database.php 的默认连接驱动选择方言:MySQL 或 PostgreSQL。其他驱动(SQLite/SQL Server)请用 silber/bouncer 官方 migration 建表 |
数据库支持
运行时权限判定走 Eloquent(illuminate/database),因此只要配置的驱动正确,MySQL 与 PostgreSQL 均可正常使用 can()/allow()/assign()/forbid()。
PostgreSQL 的 config/database.php:
测试
前置:本地 MySQL(默认 127.0.0.1:3306,库 webman_bouncer_test,用户 bouncer / bouncer_pass),
可用环境变量覆盖:
| 环境变量 | 默认值 |
|---|---|
BOUNCER_TEST_DB_HOST |
127.0.0.1 |
BOUNCER_TEST_DB_PORT |
3306 |
BOUNCER_TEST_DB_NAME |
webman_bouncer_test |
BOUNCER_TEST_DB_USER |
bouncer |
BOUNCER_TEST_DB_PASS |
bouncer_pass |
BOUNCER_TEST_CACHE |
request(request | none) |
bootstrap 自动建库建表(每次运行先清空重建),并把数据库与插件配置替换为 tests/config/ 下的
fixture。测试用 support\Context 模拟请求边界(Context::destroy()),确保每请求实例、租户
scope、剪贴板等状态不在用例间串号。
工作原理
webman 是长驻进程,进程级静态状态会跨请求残留。本插件把 bouncer 的全部可变状态
(Clipboard、缓存、租户 Scope)放进每请求实例(存于 support\Context,协程安全),
启动时只做进程级一次性配置(Illuminate 容器单例、Eloquent、用户模型映射、morph map):
License
MIT
All versions of webman-bouncer with dependencies
workerman/webman-framework Version ^2.1
illuminate/container Version ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^11.0 || ^12.0 || ^13.0
silber/bouncer Version ^1.0.2