mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 23:44:03 +00:00
29 lines
615 B
PHP
29 lines
615 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Database\Concerns;
|
|
|
|
use Closure;
|
|
use Illuminate\Foundation\Bus\PendingDispatch;
|
|
use Stancl\Tenancy\Contracts\Tenant;
|
|
|
|
/**
|
|
* @phpstan-require-implements Tenant
|
|
*/
|
|
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 is PendingDispatch ? null : T)
|
|
*/
|
|
public function run(Closure $callback): mixed
|
|
{
|
|
return tenancy()->run($this, $callback);
|
|
}
|
|
}
|