mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:54:03 +00:00
35 lines
858 B
PHP
35 lines
858 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Resolvers;
|
|
|
|
use Stancl\Tenancy\Contracts\Tenant;
|
|
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException;
|
|
|
|
class RequestDataTenantResolver extends Contracts\CachedTenantResolver
|
|
{
|
|
public static bool $shouldCache = false;
|
|
|
|
public static int $cacheTTL = 3600; // seconds
|
|
|
|
public static string|null $cacheStore = null; // default
|
|
|
|
public function resolveWithoutCache(mixed ...$args): Tenant
|
|
{
|
|
$payload = (string) $args[0];
|
|
|
|
if ($payload && $tenant = tenancy()->find($payload)) {
|
|
return $tenant;
|
|
}
|
|
|
|
throw new TenantCouldNotBeIdentifiedByRequestDataException($payload);
|
|
}
|
|
|
|
public function getArgsForTenant(Tenant $tenant): array
|
|
{
|
|
return [
|
|
[$tenant->getTenantKey()],
|
|
];
|
|
}
|
|
}
|