flametrench/tenancy
Composer 安装命令:
composer require flametrench/tenancy
包简介
Tenancy primitives for Flametrench: organizations, memberships, invitations. Spec-conformant revoke-and-re-add lifecycle and atomic invitation acceptance.
README 文档
README
Tenancy primitives for Flametrench: organizations, memberships, and invitations. Spec-conformant revoke-and-re-add lifecycle, atomic invitation acceptance, sole-owner protection, and a mem_/tup_ duality maintained without drift.
The PHP counterpart of @flametrench/tenancy — same shapes, same invariants, same operations. Both SDKs are exercised against the spec's conformance suite so applications can move between the two languages with no behavioral surprises.
Status: v0.2.0 (stable). PHP 8.3+ required. Includes the production-ready PostgresTenancyStore alongside the in-memory reference store; the Postgres adapter mirrors in-memory semantics byte-for-byte at the SDK boundary, and per ADR 0013 cooperates with adopter-side outer transactions via savepoints when nested.
Install
composer require flametrench/tenancy
Quick start
use Flametrench\Tenancy\InMemoryTenancyStore; use Flametrench\Tenancy\PreTuple; use Flametrench\Tenancy\Role; $store = new InMemoryTenancyStore(); // Alice creates Acme and becomes its owner. ['org' => $org, 'ownerMembership' => $owner] = $store->createOrg('usr_0190...alice'); // Alice invites Carol with a project-scoped grant. $inv = $store->createInvitation( orgId: $org->id, identifier: 'carol@example.com', role: Role::Guest, invitedBy: 'usr_0190...alice', expiresAt: new DateTimeImmutable('+7 days'), preTuples: [new PreTuple('viewer', 'proj', '0190...project42')], ); // Carol accepts. Membership and pre-tuples materialize atomically. $result = $store->acceptInvitation($inv->id, asUsrId: 'usr_0190...carol');
API
TenancyStore defines the contract every backend implements. Both the in-memory reference implementation and the production-ready PostgresTenancyStore ship with this package.
| Operation | Returns |
|---|---|
createOrg(creator) |
['org' => Organization, 'ownerMembership' => Membership] |
getOrg / suspendOrg / reinstateOrg / revokeOrg |
Organization |
addMember / getMembership / changeRole / suspendMembership / reinstateMembership |
Membership |
selfLeave(memId, transferTo?) |
Membership (revoked) |
adminRemove(memId, adminUsrId) |
Membership (revoked, with removedBy set) |
transferOwnership(orgId, fromMemId, toMemId) |
['fromMembership' => Membership, 'toMembership' => Membership] |
listMembers(orgId, cursor?, limit, status?) |
Page<Membership> |
createInvitation / getInvitation / declineInvitation / revokeInvitation |
Invitation |
acceptInvitation(invId, asUsrId?) |
['invitation' => Invitation, 'membership' => Membership, 'materializedTuples' => Tuple[]] |
listInvitations(orgId, cursor?, limit, status?) |
Page<Invitation> |
listTuplesForSubject(subjectType, subjectId) |
Tuple[] |
listTuplesForObject(objectType, objectId, relation?) |
Tuple[] |
Spec conformance
Mirrors the normative spec: see spec/docs/tenancy.md and the design decisions in ADR 0002 + ADR 0003.
The 31 PEST tests in this package cover every sole-owner-protection path, the replaces chain on role changes, atomic invitation acceptance with pre-tuple materialization, admin-hierarchy enforcement, ownership transfer atomicity, and removedBy attribution.
Errors
Every error is a Flametrench\Tenancy\Exceptions\TenancyException subclass with a stable flametrenchCode matching the OpenAPI Error envelope:
| Class | Code |
|---|---|
NotFoundException |
not_found |
SoleOwnerException |
conflict.sole_owner |
RoleHierarchyException |
forbidden.role_hierarchy |
DuplicateMembershipException |
conflict.duplicate_membership |
AlreadyTerminalException |
conflict.already_terminal |
InvitationExpiredException |
conflict.invitation_expired |
InvitationNotPendingException |
conflict.invitation_not_pending |
ForbiddenException |
forbidden |
PreconditionException |
precondition.<specifics> |
Development
composer install
composer test
License
Apache License 2.0. Copyright 2026 NDC Digital, LLC.
flametrench/tenancy 适用场景与选型建议
flametrench/tenancy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 236 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tenancy」 「multi-tenancy」 「organizations」 「invitations」 「memberships」 「flametrench」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flametrench/tenancy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flametrench/tenancy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flametrench/tenancy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The tenancy/tenancy views mutations
The tenancy/tenancy logs mutations
The tenancy/tenancy identification driver using environment variables
The tenancy/tenancy cache mutations
The tenancy/tenancy database driver for sqlite
A simple, single database multi-tenancy solution for Laravel 5.2+
统计信息
- 总下载量: 236
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-25