Adapters are responsible for dynamic configuration changes based on tenant table values at runtime.
On TenantSelectEvent
event dispatch, the system will iterate through all registered adapters and apply the changes.
#[AsEventListener(event: TenantSelectEvent::class, method: 'onTenantSelectEvent')]
class EnvironmentProvider
{
// ...
public function onTenantSelectEvent(TenantSelectEvent $event)
{
$tenant = $event->getTenant();
// TODO: implement null-tenant handling
if (!$tenant) {
return;
}
$this->adapterRegistry->getAdapters()->map(function (AdapterInterface $adapter) use ($tenant) {
$adapter->adapt($tenant);
});
}
}
Changes system database connection configuration DSN (Data Source Name) value
Changes the doctrine.dbal.connections.tenant.url
value at runtime:
doctrine:
dbal:
connections:
tenant:
url: '%database_url%'
NB The connection name (in this case tenant
) is configurable!
Switches current Filesystem provider to a new Gaufrette FTP filesystem provider.
When using Sonata Media Bundle, this adapter will switch the current filesystem provider to a new Gaufrette FTP filesystem provider. Set the FilesystemAdapter as the provider for the Sonata Media Bundle in the configuration file.
sonata_media:
providers:
file:
filesystem: aPajo\MultiTenancyBundle\Adapter\Filesystem\FilesystemAdapter
filesystem:
ftp:
passive: true
create: true
mode: 2
NB! This adapter supports only FTP filesystems at the moment. Feel free to contribute
Updates symfony/mailer DSN value based on the tenant information.
Changes the framework.mailer.dsn
value at runtime:
framework:
mailer:
dsn: '%env(MAILER_DSN)%'