Skip to content

Commit 3392a21

Browse files
committed
Merge branch 'feature-maintenance-middleware-except-array' of https://github.com/thannaske/framework into thannaske-feature-maintenance-middleware-except-array
2 parents fff9ef8 + e535b30 commit 3392a21

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ class CheckForMaintenanceMode
1616
*/
1717
protected $app;
1818

19+
/**
20+
* The URIs that should be accessible while maintenance mode is enabled.
21+
*
22+
* @var array
23+
*/
24+
protected $except = [];
25+
1926
/**
2027
* Create a new middleware instance.
2128
*
@@ -45,9 +52,35 @@ public function handle($request, Closure $next)
4552
return $next($request);
4653
}
4754

55+
if ($this->inExceptArray($request)) {
56+
return $next($request);
57+
}
58+
4859
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
4960
}
5061

5162
return $next($request);
5263
}
64+
65+
/**
66+
* Determine if the request has a URI that should be accessible in maintenance mode.
67+
*
68+
* @param \Illuminate\Http\Request $request
69+
* @return bool
70+
*/
71+
protected function inExceptArray($request)
72+
{
73+
foreach ($this->except as $except) {
74+
if ($except !== '/') {
75+
$except = trim($except, '/');
76+
}
77+
78+
if ($request->fullUrlIs($except) || $request->is($except)) {
79+
return true;
80+
}
81+
}
82+
83+
return false;
84+
}
85+
5386
}

0 commit comments

Comments
 (0)