mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:34:03 +00:00
Combined subdomain/domain identification
This commit is contained in:
parent
8ea4940f34
commit
f328fc9c08
4 changed files with 141 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Middleware;
|
|||
use Closure;
|
||||
use Illuminate\Http\Response;
|
||||
use Stancl\Tenancy\Exceptions\NotASubdomainException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
||||
{
|
||||
|
|
@ -51,7 +52,10 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
|||
$parts = explode('.', $hostname);
|
||||
|
||||
// If we're on localhost or an IP address, then we're not visiting a subdomain.
|
||||
if (in_array(count($parts), [1, 4])) {
|
||||
$notADomain = in_array(count($parts), [1, 4]);
|
||||
$thirdPartyDomain = ! Str::endsWith($hostname, config('tenancy.central_domains'));;
|
||||
|
||||
if ($notADomain || $thirdPartyDomain) {
|
||||
$handle = static::$onInvalidSubdomain ?? function ($e) {
|
||||
throw $e;
|
||||
};
|
||||
|
|
@ -59,9 +63,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
|||
return $handle(new NotASubdomainException($hostname));
|
||||
}
|
||||
|
||||
// todo should we verify that the subdomain belongs to one of our central domains?
|
||||
// if yes, then write a test for it.
|
||||
|
||||
return $parts[static::$subdomainIndex];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue