mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:34:04 +00:00
Identification middleware & tests
This commit is contained in:
parent
a17727b437
commit
8ea4940f34
18 changed files with 362 additions and 174 deletions
36
src/Middleware/IdentificationMiddleware.php
Normal file
36
src/Middleware/IdentificationMiddleware.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
|
||||
abstract class IdentificationMiddleware
|
||||
{
|
||||
/** @var callable */
|
||||
public static $onFail;
|
||||
|
||||
/** @var Tenancy */
|
||||
protected $tenancy;
|
||||
|
||||
/** @var TenantResolver */
|
||||
protected $resolver;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue