-
Notifications
You must be signed in to change notification settings - Fork 821
/
EnvironmentBypass.php
68 lines (60 loc) · 1.47 KB
/
EnvironmentBypass.php
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 SilverStripe\Control\Middleware\ConfirmationMiddleware;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Kernel;
/**
* Allows a bypass for a list of environment types (e.g. DEV, TEST, LIVE)
*/
class EnvironmentBypass implements Bypass
{
/**
* The list of environments allowing a bypass for a confirmation
*
* @var string[]
*/
private $environments;
/**
* Initialize the bypass with the list of environment types
*
* @param string[] ...$environments
*/
public function __construct(...$environments)
{
$this->environments = $environments;
}
/**
* Returns the list of environments
*
* @return string[]
*
*/
public function getEnvironments()
{
return $this->environments;
}
/**
* Set the list of environments allowing a bypass
*
* @param string[] $environments List of environment types
*
* @return $this
*/
public function setEnvironments($environments)
{
$this->environments = $environments;
return $this;
}
/**
* Checks whether the current environment type in the list
* of allowed ones
*
* @param HTTPRequest $request
*
* @return bool
*/
public function checkRequestForBypass(HTTPRequest $request)
{
return in_array(Director::get_environment_type(), $this->environments ?? [], true);
}
}