mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 16:24:04 +00:00
phpstan, global_cache, resolver improvements, InitializationHelpers trait
This commit is contained in:
parent
fd65cf1754
commit
87212e5390
35 changed files with 170 additions and 231 deletions
|
|
@ -4,20 +4,18 @@ 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
|
||||
{
|
||||
/** @var callable */
|
||||
public static $onFail;
|
||||
|
||||
/** @var Tenancy */
|
||||
protected $tenancy;
|
||||
|
||||
/** @var TenantResolver */
|
||||
protected $resolver;
|
||||
public static ?Closure $onFail = null;
|
||||
|
||||
public function initializeTenancy($request, $next, ...$resolverArguments)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,32 +5,21 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
|
||||
class InitializeTenancyByDomain extends IdentificationMiddleware
|
||||
{
|
||||
/** @var callable|null */
|
||||
public static $onFail;
|
||||
public static ?Closure $onFail = null;
|
||||
|
||||
/** @var Tenancy */
|
||||
protected $tenancy;
|
||||
public function __construct(
|
||||
protected Tenancy $tenancy,
|
||||
protected DomainTenantResolver $resolver,
|
||||
) {}
|
||||
|
||||
/** @var DomainTenantResolver */
|
||||
protected $resolver;
|
||||
|
||||
public function __construct(Tenancy $tenancy, DomainTenantResolver $resolver)
|
||||
{
|
||||
$this->tenancy = $tenancy;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
return $this->initializeTenancy(
|
||||
$request,
|
||||
|
|
|
|||
|
|
@ -5,16 +5,13 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class InitializeTenancyByDomainOrSubdomain
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if ($this->isSubdomain($request->getHost())) {
|
||||
return app(InitializeTenancyBySubdomain::class)->handle($request, $next);
|
||||
|
|
|
|||
|
|
@ -16,22 +16,15 @@ use Stancl\Tenancy\Tenancy;
|
|||
|
||||
class InitializeTenancyByPath extends IdentificationMiddleware
|
||||
{
|
||||
/** @var callable|null */
|
||||
public static $onFail;
|
||||
public static ?Closure $onFail = null;
|
||||
|
||||
/** @var Tenancy */
|
||||
protected $tenancy;
|
||||
public function __construct(
|
||||
protected Tenancy $tenancy,
|
||||
protected PathTenantResolver $resolver,
|
||||
) {}
|
||||
|
||||
/** @var PathTenantResolver */
|
||||
protected $resolver;
|
||||
|
||||
public function __construct(Tenancy $tenancy, PathTenantResolver $resolver)
|
||||
{
|
||||
$this->tenancy = $tenancy;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
/** @var Route $route */
|
||||
$route = $request->route();
|
||||
|
|
|
|||
|
|
@ -11,33 +11,17 @@ use Stancl\Tenancy\Tenancy;
|
|||
|
||||
class InitializeTenancyByRequestData extends IdentificationMiddleware
|
||||
{
|
||||
/** @var string|null */
|
||||
public static $header = 'X-Tenant';
|
||||
public static string $header = 'X-Tenant';
|
||||
public static string $queryParameter = 'tenant';
|
||||
public static ?Closure $onFail = null;
|
||||
|
||||
/** @var string|null */
|
||||
public static $queryParameter = 'tenant';
|
||||
public function __construct(
|
||||
protected Tenancy $tenancy,
|
||||
protected RequestDataTenantResolver $resolver,
|
||||
) {}
|
||||
|
||||
/** @var callable|null */
|
||||
public static $onFail;
|
||||
|
||||
/** @var Tenancy */
|
||||
protected $tenancy;
|
||||
|
||||
/** @var TenantResolver */
|
||||
protected $resolver;
|
||||
|
||||
public function __construct(Tenancy $tenancy, RequestDataTenantResolver $resolver)
|
||||
{
|
||||
$this->tenancy = $tenancy;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if ($request->method() !== 'OPTIONS') {
|
||||
return $this->initializeTenancy($request, $next, $this->getPayload($request));
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Middleware;
|
|||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Str;
|
||||
use Stancl\Tenancy\Exceptions\NotASubdomainException;
|
||||
|
|
@ -21,15 +22,10 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
|||
*/
|
||||
public static $subdomainIndex = 0;
|
||||
|
||||
/** @var callable|null */
|
||||
public static $onFail;
|
||||
public static ?Closure $onFail = null;
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
/** @return Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
$subdomain = $this->makeSubdomain($request->getHost());
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ class PreventAccessFromCentralDomains
|
|||
{
|
||||
/**
|
||||
* Set this property if you want to customize the on-fail behavior.
|
||||
*
|
||||
* @var callable|null
|
||||
*/
|
||||
public static $abortRequest;
|
||||
public static ?Closure $abortRequest;
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if (in_array($request->getHost(), config('tenancy.central_domains'))) {
|
||||
$abortRequest = static::$abortRequest ?? function () {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ class ScopeSessions
|
|||
{
|
||||
public static $tenantIdKey = '_tenant_id';
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
/** @return \Illuminate\Http\Response|mixed */
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
if (! tenancy()->initialized) {
|
||||
throw new TenancyNotInitializedException('Tenancy needs to be initialized before the session scoping middleware is executed');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue