mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:14:03 +00:00
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Resolvers;
|
|
|
|
use Illuminate\Routing\Route;
|
|
use Stancl\Tenancy\Contracts\Tenant;
|
|
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException;
|
|
|
|
class PathTenantResolver extends Contracts\CachedTenantResolver
|
|
{
|
|
public function resolveWithoutCache(mixed ...$args): Tenant
|
|
{
|
|
/** @var Route $route */
|
|
$route = $args[0];
|
|
|
|
if ($id = (string) $route->parameter(static::tenantParameterName())) {
|
|
$route->forgetParameter(static::tenantParameterName());
|
|
|
|
if ($tenant = tenancy()->find($id)) {
|
|
return $tenant;
|
|
}
|
|
}
|
|
|
|
throw new TenantCouldNotBeIdentifiedByPathException($id);
|
|
}
|
|
|
|
public function getArgsForTenant(Tenant $tenant): array
|
|
{
|
|
return [
|
|
[$tenant->getTenantKey()],
|
|
];
|
|
}
|
|
|
|
public static function tenantParameterName(): string
|
|
{
|
|
return config('tenancy.identification.resolvers.' . static::class . '.tenant_parameter_name') ?? 'tenant';
|
|
}
|
|
}
|