mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 16:24:04 +00:00
Initial commit
This commit is contained in:
commit
deb3ad77f5
19 changed files with 1283 additions and 0 deletions
37
src/Middleware/InitializeTenancy.php
Normal file
37
src/Middleware/InitializeTenancy.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class InitializeTenancy
|
||||
{
|
||||
public function __construct(Closure $onFail = null)
|
||||
{
|
||||
$this->onFail = $onFail ?: function ($e) { throw $e; };
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
try {
|
||||
tenancy()->init();
|
||||
} catch (\Exception $e) {
|
||||
// Pass the exception to the onFail function if it takes any parameters.
|
||||
$callback = $this->onFail;
|
||||
if ((new \ReflectionFunction($callback))->getNumberOfParameters() > 0) {
|
||||
$callback($e);
|
||||
} else {
|
||||
$callback();
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue