Skip to content

v3.0.0 - Automatic Tenant Resolution, Pluggable Config Providers & Full Test Coverage

Choose a tag to compare

@RamyHakam RamyHakam released this 21 Feb 15:26
· 3 commits to master since this release

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 request
  • TenantAwareCacheDecorator — Automatic per-tenant cache key isolation wrapping any PSR-6 pool
  • TenantTestTrait — PHPUnit helper with runInTenant() for cleaner multi-tenant test setup

Examples & Documentation

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

  1. Remove any direct usage of DbService → use TenantDatabaseManagerInterface
  2. Replace tenant:schema:update → use tenant:migrations:migrate
  3. (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