mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 04:44:03 +00:00
* Stop bypassing tenancy initialization when host is central domain in domain ID MW * Delete dataset for testing global domain ID MW + route-level prevent access MW * Provide ID MW statically in TenantAssetController * Fix code style (php-cs-fixer) --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Stancl\Tenancy\Concerns\UsableWithEarlyIdentification;
|
|
use Stancl\Tenancy\Concerns\UsableWithUniversalRoutes;
|
|
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
|
use Stancl\Tenancy\Tenancy;
|
|
|
|
class InitializeTenancyByDomain extends IdentificationMiddleware implements UsableWithUniversalRoutes
|
|
{
|
|
use UsableWithEarlyIdentification;
|
|
|
|
public static ?Closure $onFail = null;
|
|
|
|
public function __construct(
|
|
protected Tenancy $tenancy,
|
|
protected DomainTenantResolver $resolver,
|
|
) {
|
|
}
|
|
|
|
/** @return \Illuminate\Http\Response|mixed */
|
|
public function handle(Request $request, Closure $next): mixed
|
|
{
|
|
if ($this->shouldBeSkipped(tenancy()->getRoute($request))) {
|
|
// Allow accessing central route in kernel identification
|
|
return $next($request);
|
|
}
|
|
|
|
return $this->initializeTenancy(
|
|
$request,
|
|
$next,
|
|
$request->getHost()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Domain identification request has a tenant if it's
|
|
* not hitting a domain specifically defined as central in the config.
|
|
*/
|
|
public function requestHasTenant(Request $request): bool
|
|
{
|
|
return ! in_array($request->host(), config('tenancy.central_domains'));
|
|
}
|
|
}
|