Completed
Branch develop (82845d)
by Mohamed
03:11
created

CheckForMaintenanceMode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Symfony\Component\HttpKernel\Exception\HttpException;
16
use Illuminate\Http\Request;
17
18
/**
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class CheckForMaintenanceMode extends MiddlewareAbstract
22
{
23
    /**
24
     * Handle an incoming request.
25
     *
26
     * @param \Illuminate\Http\Request $request
27
     * @param \Closure                 $next
28
     *
29
     * @return mixed
30
     *
31
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
32
     */
33
    public function handle(Request $request, Closure $next)
34
    {
35
        $siteDown = $this->app->isDownForMaintenance();
36
        $isLogin  = $request->is('/', 'logout', 'signin');
37
38
        // Allow admin & login page to always view the site event in maintenance mode
39
        if ($siteDown && !$isLogin && ($this->auth->guest() || !$this->getLoggedUser()->isAdmin())) {
40
            throw new HttpException(503);
41
        }
42
43
        // Show message to administrator
44 63
        if ($siteDown) {
45
            $this->app['session']->flash('notice-error', trans('tinyissue.site_maintenance_message'));
46 63
        }
47 63
48 63
        return $next($request);
49
    }
50
}
51