Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function __invoke($request, $response, $next)
- {
- $response = $next($request, $response);
- $tenantMap = TableRegistry::get('TenantMappings');
- $mapping = $tenantMap->findByName($request->subdomains()[0])->firstOrFail();
- ConnectionManager::config("alias_".$request->subdomains()[0], [
- 'className' => 'CakeDatabaseConnection',
- 'driver' => 'CakeDatabaseDriverMysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'username' => '***username***',
- 'password' => '***password***',
- 'database' => '***database***',
- 'encoding' => 'utf8',
- 'timezone' => 'UTC',
- 'cacheMetadata' => true,
- ]);
- ConnectionManager::alias ("alias_".$request->subdomains()[0], "default");
- Configure::write('Account.active', $mapping->account_id);
- return $response;
- }
Add Comment
Please, Sign In to add comment