mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 16:24:04 +00:00
Tenant-specific maintenance mode
This commit is contained in:
parent
ac58f6992b
commit
2fedd5ce88
3 changed files with 96 additions and 0 deletions
36
src/Middleware/CheckTenantForMaintenanceMode.php
Normal file
36
src/Middleware/CheckTenantForMaintenanceMode.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
|
||||
use Illuminate\Http\Request;
|
||||
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (! tenant()) {
|
||||
throw new TenancyNotInitializedException;
|
||||
}
|
||||
|
||||
if (tenant('maintenance_mode')) {
|
||||
$data = tenant('maintenance_mode');
|
||||
|
||||
if (isset($data['allowed']) && IpUtils::checkIp($request->ip(), (array) $data['allowed'])) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($this->inExceptArray($request)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue