mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
* Add bring up from maintenance function * Add up and down tenant maintenance commands * Rename commands signatures * Update TenancyServiceProvider.php * Complying to Laravel maintenance code and parameters * Update MaintenanceModeTest.php * Add maintenance mode via commands test * Update CheckTenantForMaintenanceMode.php * Update MaintenanceModeTest.php * Cookie bypass only for > Laravel 8 * minor formatting change, trigger CI * clean * Update MaintenanceModeTest.php * Add comments for using the 'tenants' option in runForMultiple * improve code * php-cs-fixer * fix php cs fixer config * improve test logic * remove version check since v4 will be L9+ Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: lukinovec <lukinovec@gmail.com> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
|
|
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
|
{
|
|
public function handle($request, Closure $next)
|
|
{
|
|
if (! tenant()) {
|
|
throw new TenancyNotInitializedException;
|
|
}
|
|
|
|
if (tenant('maintenance_mode')) {
|
|
$data = tenant('maintenance_mode');
|
|
|
|
if (isset($data['secret']) && $request->path() === $data['secret']) {
|
|
return $this->bypassResponse($data['secret']);
|
|
}
|
|
|
|
if ($this->hasValidBypassCookie($request, $data) ||
|
|
$this->inExceptArray($request)) {
|
|
return $next($request);
|
|
}
|
|
|
|
if (isset($data['redirect'])) {
|
|
$path = $data['redirect'] === '/'
|
|
? $data['redirect']
|
|
: trim($data['redirect'], '/');
|
|
|
|
if ($request->path() !== $path) {
|
|
return redirect($path);
|
|
}
|
|
}
|
|
|
|
if (isset($data['template'])) {
|
|
return response(
|
|
$data['template'],
|
|
(int) ($data['status'] ?? 503),
|
|
$this->getHeaders($data)
|
|
);
|
|
}
|
|
|
|
throw new HttpException(
|
|
(int) ($data['status'] ?? 503),
|
|
'Service Unavailable',
|
|
null,
|
|
$this->getHeaders($data)
|
|
);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|