forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectSiteMiddleware.php
More file actions
68 lines (56 loc) · 1.67 KB
/
Copy pathDetectSiteMiddleware.php
File metadata and controls
68 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Ushahidi\App\Multisite;
use Closure;
class DetectSiteMiddleware
{
/**
* @var \Ushahidi\App\Multisite\MultisiteManager;
*/
protected $multisite;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(MultisiteManager $multisite)
{
$this->multisite = $multisite;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param mixed ...$features
* @return mixed
*/
public function handle($request, Closure $next)
{
// If we're not running in multsite mode...
if (!$this->multisite->enabled()) {
// ... just continue with the request
return $next($request);
}
try {
$this->multisite->setSiteFromHost($request->getHost());
} catch (SiteNotFoundException $e) {
abort(404, "Deployment not found");
}
$site = $this->multisite->getSite();
// If the deployment hasn't been deployed yet
if ($site->getStatus() === 'pending') {
abort(503, $site->getName() . " is not ready");
}
// If the site is down for maintenance
if ($site->getStatus() === 'maintenance') {
abort(503, $site->getName() . " is down for maintenance");
}
// Finally, confirm the db is ready
if (!$site->isDbReady()) {
abort(503, $site->getName() . " is not ready");
}
// Otherwise just continue with the request
return $next($request);
}
}