1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:24:04 +00:00

Initial commit

This commit is contained in:
Samuel Štancl 2019-01-17 22:24:12 +01:00
commit deb3ad77f5
19 changed files with 1283 additions and 0 deletions

View 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);
}
}