tenant = $tenant; } public function forget(): void { $this->tenant = null; $this->required = false; } public function get(): ?Tenant { return $this->tenant; } public function id(): ?int { return $this->tenant?->id; } public function requirePresence(bool $required = true): void { $this->required = $required; } public function isRequired(): bool { return $this->required; } /** * Run a callback as $tenant, then restore whoever was current before. * * @template T * * @param callable(): T $callback * @return T */ public function run(Tenant $tenant, callable $callback): mixed { $previous = $this->tenant; $this->tenant = $tenant; try { return $callback(); } finally { $this->tenant = $previous; } } }