-
-
Notifications
You must be signed in to change notification settings - Fork 443
/
Copy pathPathTenantResolver.php
46 lines (34 loc) · 1.08 KB
/
PathTenantResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?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 static $tenantParameterName = 'tenant';
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
public function resolveWithoutCache(...$args): Tenant
{
/** @var Route $route */
$route = $args[0];
if ($id = $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->id],
];
}
}