mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 08:44:02 +00:00
36 lines
861 B
PHP
36 lines
861 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Middleware;
|
|
|
|
use Closure;
|
|
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
|
use Stancl\Tenancy\Contracts\TenantResolver;
|
|
use Stancl\Tenancy\Tenancy;
|
|
|
|
/**
|
|
* @property Tenancy $tenancy
|
|
* @property TenantResolver $resolver
|
|
*/
|
|
abstract class IdentificationMiddleware
|
|
{
|
|
public static ?Closure $onFail = null;
|
|
|
|
public function initializeTenancy($request, $next, ...$resolverArguments)
|
|
{
|
|
try {
|
|
$this->tenancy->initialize(
|
|
$this->resolver->resolve(...$resolverArguments)
|
|
);
|
|
} catch (TenantCouldNotBeIdentifiedException $e) {
|
|
$onFail = static::$onFail ?? function ($e) {
|
|
throw $e;
|
|
};
|
|
|
|
return $onFail($e, $request, $next);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|