Download the PHP package zhortein/multi-tenant-bundle without Composer
On this page you can find all versions of the php package zhortein/multi-tenant-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zhortein/multi-tenant-bundle
More information about zhortein/multi-tenant-bundle
Files in zhortein/multi-tenant-bundle
Package multi-tenant-bundle
Short Description A fail-closed Symfony 7.4 LTS and Symfony 8.x multi-tenant bundle with PostgreSQL >= 16 defense-in-depth support.
License MIT
Homepage https://github.com/zhortein/multi-tenant-bundle
Informations about the package multi-tenant-bundle
Zhortein Multi-Tenant Bundle
A fail-closed Symfony 7.4 LTS and Symfony 8.x bundle for building multi-tenant applications, with PostgreSQL RLS as an optional defense in depth.
RC9 supports Symfony Scheduler's persistent RedispatchMessage path without
weakening tenant/global classification. Every main HTTP request, received
Messenger message, reused Console command, and
TenantExecutionBoundaryInterface callback starts from NONE.
TenantContext remains a shared mutable service; it is not recreated for every
request.
Features
- ๐ข Multiple Tenant Resolution Strategies: Subdomain, path-based, header-based, domain-based, DNS TXT, hybrid, or custom resolvers
- ๐๏ธ Database Strategies: Shared database with filtering or separate databases per tenant
- โก Performance Optimized: Built-in caching for tenant settings and configurations
- ๐ง Doctrine Integration: Automatic tenant filtering with Doctrine ORM
- ๐ง Tenant-Aware Services: Mailer with automatic tenant propagation, Messenger with context preservation, and file storage integration
- ๐ฏ Event-Driven: Database switching events and automatic tenant context resolution
- ๐ ๏ธ Advanced Commands: Schema management, migrations, and fixtures for tenants
- ๐งช Comprehensive Test Kit: First-class testing utilities to prove tenant isolation works
- ๐ RLS Integration: PostgreSQL Row-Level Security for defense-in-depth
- ๐ PHPStan Level Max: Static analysis at maximum level
Fail-closed security contract
Tenant-aware Doctrine reads and writes require a valid current tenant and reject invalid mappings, stale filter state, tenant changes, and cross-tenant mutations. Global ORM operations are explicit callbacks through GlobalDoctrineScopeInterface; direct filter disabling is outside the supported contract.
Messenger messages implement exactly one of TenantAwareMessageInterface or GlobalMessageInterface. Tenant-aware messages require consistent tenant metadata at send and receive time, while global messages must never carry a tenant stamp. See the RC1 to RC2 migration guide.
Messenger transport selection is explicit: tenant_transport preserves the historical per-tenant map/default behavior, while symfony_routing leaves transport stamps untouched so framework.messenger.routing and #[AsMessage] work natively. Native mode has no bundle fallback; an unrouted message with a handler may run synchronously. See RC7 to RC8 migration guide.
Persistent Symfony Scheduler work uses a classified application message inside
Symfony's RedispatchMessage, with an explicit persistent destination. Directly
scheduling the application message can execute its handler in the Scheduler
Worker because the Scheduler envelope is already marked as received. See the
RC8 to RC9 migration guide.
Installation
Install the bundle via Composer:
The core dependency set and optional Mailer, Twig, Monolog, and PSR-16 integrations are listed in the dependency classification.
Enable the bundle in your config/bundles.php:
Quick Start
1. Create Your Tenant Entity
2. Configure the Bundle
Create config/packages/zhortein_multi_tenant.yaml:
3. Create Tenant-Aware Entities
4. Use in Controllers
๐ Documentation
๐ Getting Started
- Installation & Setup - Complete installation guide
- Compatibility Policy - Tested PHP, Symfony, and Doctrine combinations
- Configuration Reference - All configuration options
- Database Strategies - Shared DB vs Multi-DB
๐๏ธ Core Concepts
- Tenant Context - Tenant resolution and access
- Tenant Resolution - Resolution strategies
- DNS TXT Resolver - DNS-based tenant resolution
- Domain Resolvers - Domain and hybrid resolvers
- Doctrine Tenant Filter - Automatic filtering
- Tenant Settings - Configuration system
๐ง Service Integration
- Mailer - Tenant-aware email with templated support
- Messenger - Tenant-aware queues with automatic context propagation
- Scheduler - Classified redispatch through a persistent transport
- Storage - Fail-closed file storage isolation
- Security Contract Migration - Required storage, cache, mailer, and observability migration
- RC4 to RC5 Migration - Persistent lifecycle reset and early/late HTTP resolution
- RC7 to RC8 Migration - Choose tenant-specific or native Symfony Messenger routing
- RC8 to RC9 Migration - Adopt fail-closed persistent Scheduler redispatch
- Persistent Process Lifecycle - Complete state inventory, reset order, and failure behavior
๐๏ธ Database Management
- Migrations - Database migrations
- Fixtures - Test data loading
๐ ๏ธ Development Tools
- CLI Commands - Console commands
- Testing - Testing strategies and Test Kit
- FAQ - Common questions
๐ Examples
- Basic Usage - Code examples
- Mailer Examples - Email templates and configuration
- Messenger Examples - Message routing and handling
- Service Integration - Practical implementations
Testing with the Bundle
The optional public Test Kit provides three intentionally small APIs:
TenantContextScopeexecutes a callback under a consumer-defined tenant and restores the previous context in all outcomes;TenantKernelTestCaseintegrates that scope with Symfony kernel tests;TenantWebTestCaseintegrates the same lifecycle with Symfony functional tests without selecting a resolver or database strategy.
Quick Example
Running Tests
See the Testing Documentation for installation, lifecycle, and consumer examples.
Code Quality
Contributing
- Fork the repository
- Create a feature branch
- Write tests for your changes
- Ensure all tests pass and code meets quality standards
- Submit a pull request
See CONTRIBUTING.md for detailed guidelines.
License
This bundle is released under the MIT License. See the LICENSE file for details.
Support
- Documentation: Complete documentation
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Object storage
The optional object storage core provides durable tenant-aware references and a backend-independent contract, disabled by default. The optional Flysystem/S3-compatible bridge adds real MinIO proofs and leaves the historical file API unchanged. RC12 remains a prerelease. Its optional audit API adds lazy location inventory, explicit scopes and logical identity observations. Audit is disabled by default; historical objects without identity remain readable. Upgrading enables no integration and runs no SQL, object or metadata migration. See the RC11 to RC12 migration guide, including the trust boundary, progressive adoption and application rollback.
Changelog
See CHANGELOG.md for version history and upgrade instructions.
All versions of multi-tenant-bundle with dependencies
doctrine/dbal Version ^3.8 || ^4.4
doctrine/doctrine-bundle Version ^2.19 || ^3.3
doctrine/doctrine-migrations-bundle Version ^3.4 || ^4.0
doctrine/migrations Version ^3.0
doctrine/orm Version ^3.5
doctrine/persistence Version ^3.3 || ^4.0
psr/cache Version ^3.0
psr/event-dispatcher Version ^1.0
psr/log Version ^3.0
symfony/config Version ^7.4 || ^8.0
symfony/console Version ^7.4 || ^8.0
symfony/dependency-injection Version ^7.4 || ^8.0
symfony/event-dispatcher Version ^7.4 || ^8.0
symfony/event-dispatcher-contracts Version ^3.4
symfony/filesystem Version ^7.4 || ^8.0
symfony/finder Version ^7.4 || ^8.0
symfony/http-foundation Version ^7.4 || ^8.0
symfony/http-kernel Version ^7.4 || ^8.0
symfony/messenger Version ^7.4 || ^8.0
symfony/service-contracts Version ^3.4