v3.0.0 - Automatic Tenant Resolution, Pluggable Config Providers & Full Test Coverage
What's New
Automatic Tenant Resolution
Resolve tenants from HTTP requests automatically no manual SwitchDbEvent dispatching required. Five built-in strategies out of
the box:
| Strategy | Example | Description |
|---|---|---|
subdomain |
tenant1.example.com |
Extracts tenant from subdomain |
path |
/tenant1/dashboard |
Extracts tenant from URL path segment |
header |
X-Tenant-ID: tenant1 |
Extracts tenant from HTTP header |
host |
client.com → tenant1 |
Maps full hostname to tenant |
chain |
Multiple strategies | Tries resolvers in order with fallback |
Implement TenantResolverInterface for custom resolution logic (JWT, API keys, cookies, etc.).
Disabled by default, existing SwitchDbEvent usage continues to work unchanged.
Pluggable Tenant Config Providers
New TenantConfigProviderInterface lets you load tenant configurations from any source: Doctrine (default), Redis, static arrays,
environment variables, or your own backend.
New APIs & Attributes
TenantContextInterface— Access the current tenant ID from any service without coupling to the HTTP requestTenantAwareCacheDecorator— Automatic per-tenant cache key isolation wrapping any PSR-6 poolTenantTestTrait— PHPUnit helper withrunInTenant()for cleaner multi-tenant test setup
Examples & Documentation
- 15 ready-to-use code examples in
examples/covering every bundle feature from entity setup to a full tenant
onboarding flow - Comprehensive documentation site at
ramyhakam.github.io/multi_tenancy_bundle
Breaking Changes
Removed: DbService
The legacy DbService (158 lines) has been removed. It was superseded by DoctrineTenantDatabaseManager since v2.5.
Migration: Replace any DbService usage with TenantDatabaseManagerInterface.
Removed: tenant:schema:update command
The UpdateSchemaCommand hardcoded App\Entity\Main\Tenant and was unusable in most projects.
Migration: Use tenant:migrations:migrate for all schema management.
Test Coverage
345 tests across 3 suites — all green:
| Suite | Tests | Assertions |
|---|---|---|
| Unit | 216 | 455 |
| Integration | 106 | 203 |
| Functional (MySQL + PostgreSQL) | 23 | 70 |
| Total | 345 | 728 |
Functional tests run against real MySQL 8.0 and PostgreSQL 15 databases.
Upgrade from v2.9.x
- Remove any direct usage of
DbService→ useTenantDatabaseManagerInterface - Replace
tenant:schema:update→ usetenant:migrations:migrate - (Optional) Enable automatic resolution:
hakam_multi_tenancy: resolver: enabled: true strategy: header # or subdomain, path, host, chain
Full Changelog: v2.9.0...v3.0.0