mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 02:44:02 +00:00
* fix issue and add test * Update CreateTenantConnection.php * add purge call * Update ManualModeTest.php * use tenant connection and central connection listener * Update ManualModeTest.php * fix test * improvements * Update ManualModeTest.php * add comment * simplify comment Co-authored-by: Samuel Štancl <samuel@archte.ch>
26 lines
615 B
PHP
26 lines
615 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Listeners;
|
|
|
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
|
use Stancl\Tenancy\Database\DatabaseManager;
|
|
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
|
|
|
class CreateTenantConnection
|
|
{
|
|
public function __construct(
|
|
protected DatabaseManager $database,
|
|
) {
|
|
}
|
|
|
|
public function handle(TenancyEvent $event): void
|
|
{
|
|
/** @var TenantWithDatabase $tenant */
|
|
$tenant = $event->tenancy->tenant;
|
|
|
|
$this->database->purgeTenantConnection();
|
|
$this->database->createTenantConnection($tenant);
|
|
}
|
|
}
|