1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 23:34:03 +00:00

Simplify Tenant contract (remove run method), move run logic to Tenancy, add generics

This commit is contained in:
Samuel Štancl 2024-03-01 08:42:11 +01:00
parent 32a063b834
commit af3b693dd1
9 changed files with 39 additions and 26 deletions

View file

@ -13,21 +13,14 @@ trait TenantRun
* Run a callback in this tenant's context.
*
* This method is atomic and safely reverts to the previous context.
*
* @template T
* @param Closure(Tenant): T $callback
* @return T
*/
public function run(Closure $callback): mixed
{
/** @var Tenant $this */
$originalTenant = tenant();
tenancy()->initialize($this);
$result = $callback($this);
if ($originalTenant) {
tenancy()->initialize($originalTenant);
} else {
tenancy()->end();
}
return $result;
return tenancy()->run($this, $callback);
}
}