-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerifyProStatus.php
More file actions
45 lines (38 loc) · 1.07 KB
/
VerifyProStatus.php
File metadata and controls
45 lines (38 loc) · 1.07 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
<?php
namespace LycheeVerify\Http\Middleware;
use Illuminate\Http\Request;
use LycheeVerify\Contract\Status;
use LycheeVerify\Contract\VerifyException;
use LycheeVerify\Exceptions\SupporterOnlyOperationException;
use LycheeVerify\Verify;
/**
* This class checks whether the use on a supporter installation.
* If it is not, then the request is aborted.
*/
class VerifyProStatus
{
private Verify $verify;
public function __construct(?Verify $verify)
{
$this->verify = $verify ?? new Verify();
}
/**
* Handle an incoming request.
*
* @param Request $request the incoming request to serve
* @param \Closure $next the next operation to be applied to the
* request
*
* @return mixed
*
* @throws VerifyException
*/
public function handle(Request $request, \Closure $next, string $required_status): mixed
{
$required_status = Status::tryFrom($required_status) ?? Status::PRO_EDITION;
if ($this->verify->check($required_status)) {
return $next($request);
}
throw new SupporterOnlyOperationException(Status::PRO_EDITION);
}
}