customable/tenancy-bundle (2.3.1)
Published 2026-03-14 17:54:38 +00:00 by jack
Installation
{
"repositories": [{
"type": "composer",
"url": " "
}
]
}composer require customable/tenancy-bundle:2.3.1About this package
Multi-tenant Symfony bundle with schema-per-tenant support for PostgreSQL
Customable Tenancy Bundle
A flexible, production-ready multi-tenant bundle for Symfony 7.3+ / 8.0+ applications.
Inspired by Tenancy for Laravel and Sprout Laravel.
Features
- Three isolation strategies: Schema (PostgreSQL/MySQL), Database, or Column-based
- Flexible tenant identification: Subdomain, domain, header, path, query, cookie, session, or POST body
- Automatic resource isolation: Database, cache, filesystem, sessions, cookies, mail
- Multiple tenancy contexts: Support for organization/workspace/team hierarchies
- Developer-friendly:
#[CurrentTenant]injection, Twig functions, Messenger integration - Universal routes: Mark routes accessible regardless of tenant context
- Tenant-aware assets: Vite/Webpack integration for tenant-specific builds
- Event-driven: Lifecycle hooks for extensibility
What's New in v2.0.0
- TenancyManager for multiple named tenancy contexts (organization → workspace → team)
- New resolvers: Cookie, Session, and RequestData (POST/JSON body)
- Universal routes via
#[UniversalRoute]attribute - Tenant-aware assets with Twig functions (
tenant_asset(),tenant_build_path()) - Database cache adapter with tenant isolation
- PersistentQueueTenancyBootstrapper for Symfony Messenger
- TenantConfigBootstrapper for runtime parameter overrides
- MailConfigBootstrapper for tenant-specific mail settings
- DisallowSqliteAttach security middleware
Requirements
- PHP 8.4+
- Symfony 7.3+ or 8.0+
- Doctrine ORM 3.0+
- PostgreSQL 12+, MySQL 8.0+, or MariaDB 10.5+
Installation
composer require customable/tenancy-bundle
Quick Start
1. Create your Tenant entity implementing TenantInterface:
use Customable\TenancyBundle\Contract\TenantInterface;
#[ORM\Entity]
class Tenant implements TenantInterface
{
public function getTenantIdentifier(): string { return $this->key; }
public function getTenantKey(): string|int { return $this->id; }
public function getTenantSchema(): string { return 'tenant_' . $this->key; }
public function getTenantData(): array { return $this->data; }
}
2. Create your repository extending AbstractTenantRepository:
use Customable\TenancyBundle\Repository\AbstractTenantRepository;
class TenantRepository extends AbstractTenantRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Tenant::class);
}
}
3. Configure the bundle:
# config/packages/tenancy.yaml
tenancy:
tenant_class: App\Entity\Tenant
identification:
central_domains: [example.com]
routing:
domain_pattern: "{tenant}.example.com"
4. Use in controllers:
use Customable\TenancyBundle\Attribute\CurrentTenant;
#[Route('/dashboard')]
public function dashboard(#[CurrentTenant] TenantInterface $tenant): Response
{
return new Response("Welcome to {$tenant->getTenantIdentifier()}!");
}
Documentation
See the docs/ folder for detailed documentation:
- Configuration Reference
- Tenant Entity & Repository
- Tenant Identification
- Tenancy Strategies
- Working with Context
- URL Generation
- Bootstrappers
- Messenger Integration
- Console Commands
- Events
- Advanced Topics
Console Commands
php bin/console tenancy:tenant:create acme "Acme Corp"
php bin/console tenancy:tenant:list
php bin/console tenancy:migrate all
php bin/console tenancy:make:migration tenant
License
MIT License. See LICENSE file.
Dependencies
Dependencies
| ID | Version |
|---|---|
| doctrine/dbal | ^4.0 |
| doctrine/doctrine-bundle | ^2.12 || ^3.0 |
| doctrine/orm | ^3.0 |
| php | >=8.4 |
| symfony/config | ^7.3 || ^8.0 |
| symfony/console | ^7.3 || ^8.0 |
| symfony/dependency-injection | ^7.3 || ^8.0 |
| symfony/event-dispatcher | ^7.3 || ^8.0 |
| symfony/framework-bundle | ^7.3 || ^8.0 |
| symfony/http-kernel | ^7.3 || ^8.0 |
| symfony/messenger | ^7.3 || ^8.0 |
Development dependencies
| ID | Version |
|---|---|
| friendsofphp/php-cs-fixer | ^3.92 |
| monolog/monolog | ^3.10 |
| phpstan/phpstan | ^2.0 |
| phpunit/phpunit | ^11.0 || ^12.0 |
| symfony/cache | ^7.3 || ^8.0 |
| symfony/security-bundle | ^7.3 || ^8.0 |
| symfony/security-core | ^7.3 || ^8.0 |
| symfony/var-dumper | ^7.3 || ^8.0 |
| twig/twig | ^3.0 |