equidna/bee-hive
Composer 安装命令:
composer require equidna/bee-hive
包简介
Reusable multi-tenant foundation for Laravel applications.
README 文档
README
Reusable multi-tenant foundation package for Laravel projects.
What It Includes
- Tenant resolver contract
- Tenant context container
- Eloquent global scope for tenant filtering
- BelongsToTenant trait with automatic tenant key fill
- Service provider with publishable config
Architecture
flowchart LR
A[Laravel Container] --> B[BeeHiveServiceProvider]
B --> C[TenantResolverInterface]
C --> D[Configured Resolver]
D --> E[TenantContext]
E --> F[TenantScope]
E --> G[BelongsToTenant Trait]
F --> H[Query Filtering by tenant key]
G --> I[Auto-fill tenant key on create]
F --> J{Tenant ID resolved?}
J -->|Yes| H
J -->|No| L[BeeHiveException]
L --> M[RFC 7807 Problem Details Response]
Loading
Flow summary:
- The service provider binds the configured tenant resolver and initializes
TenantContext. TenantScopereads the tenant from context to enforce query-level isolation.BelongsToTenantuses the same context to auto-assign tenant key values on model creation.- Missing tenant resolution always throws
BeeHiveExceptionwith an RFC 7807problem_detailsJSON response.
Error Response
When tenant resolution fails, BeeHiveException returns an RFC 7807 problem_details JSON response:
{
"type": "urn:beehive:error:tenant_not_resolved",
"title": "BeeHive Exception",
"status": 422,
"detail": "BeeHive tenant was not resolved.",
"code": "tenant_not_resolved"
}
Config keys (in config/bee-hive.php):
errors.status: HTTP status code for tenant resolution errors (default:422)logging.enabled: enable package log emission (default:true)logging.level: package log level (warningby default)logging.sample_rate: sampling ratio between0and1(default:1.0)
Environment variables:
BEE_HIVE_ERROR_STATUSBEE_HIVE_LOGGING_ENABLEDBEE_HIVE_LOG_LEVELBEE_HIVE_LOG_SAMPLE_RATE
Quality Checks
Run repository quality checks locally:
composer validate --no-check-publishcomposer audit --no-interaction./vendor/bin/phpcs --standard=ruleset.xml src config tests./vendor/bin/phpstan analyse --memory-limit=512M./vendor/bin/phpunit
CI additionally runs workflow linting (actionlint) to prevent invalid GitHub workflow syntax from reaching main.
Or run the aggregated command:
composer qacomposer qa:fastfor validate + lint + tests without audit/static analysis
Security Behavior
- Tenant-scoped reads and writes require a resolved tenant.
- Missing tenant resolution throws
BeeHiveException. - Model creation always applies the resolved tenant value, even if a different tenant value is provided in input.
Observability
BeeHive logs warning events when:
- A tenant-scoped query runs without a resolved tenant.
- A tenant-scoped model is created without a resolved tenant.
- A model create payload includes a tenant value different from the resolved context.
Each event includes a stable event_code field for alerting and dashboard rules.
Sampling behavior (logging.sample_rate) is tested deterministically in the test suite to avoid flaky observability checks.
The emitted package level still passes through the global Laravel logging configuration (channels, handlers, and minimum levels).
Event Catalog
| event_code | Trigger | Suggested severity | Context fields |
|---|---|---|---|
BEEHIVE_TENANT_UNRESOLVED_QUERY |
A tenant-scoped query runs without a resolved tenant | warning | model, tenant_key, resolver |
BEEHIVE_TENANT_UNRESOLVED_CREATE |
A tenant-scoped model create operation runs without a resolved tenant | warning | model, tenant_key |
BEEHIVE_TENANT_SPOOF_ATTEMPT |
Input tenant differs from resolved tenant during create | warning | model, tenant_key, incoming_tenant_id, resolved_tenant_id |
Suggested alerting thresholds:
- Alert immediately on any sustained
BEEHIVE_TENANT_UNRESOLVED_QUERYvolume in production. - Investigate any
BEEHIVE_TENANT_SPOOF_ATTEMPTevent as potentially malicious client behavior.
equidna/bee-hive 适用场景与选型建议
equidna/bee-hive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 955 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 equidna/bee-hive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 equidna/bee-hive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 955
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 3
- 推荐数: 1
其他信息
- 授权协议: proprietary
- 更新时间: 2026-04-13