Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

EnvironmentBypass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Control\Middleware\ConfirmationMiddleware;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Core\Kernel;
8
9
/**
10
 * Allows a bypass for a list of environment types (e.g. DEV, TEST, LIVE)
11
 */
12
class EnvironmentBypass implements Bypass
13
{
14
    /**
15
     * The list of environments allowing a bypass for a confirmation
16
     *
17
     * @var string[]
18
     */
19
    private $environments;
20
21
22
    /**
23
     * Initialize the bypass with the list of environment types
24
     *
25
     * @param string[] ...$environments
26
     */
27
    public function __construct(...$environments)
28
    {
29
        $this->environments = $environments;
30
    }
31
32
    /**
33
     * Returns the list of environments
34
     *
35
     * @return string[]
36
     *
37
     */
38
    public function getEnvironments()
39
    {
40
        return $this->environments;
41
    }
42
43
    /**
44
     * Set the list of environments allowing a bypass
45
     *
46
     * @param string[] $environments List of environment types
47
     *
48
     * @return $this
49
     */
50
    public function setEnvironments($environments)
51
    {
52
        $this->environments = $environments;
53
        return $this;
54
    }
55
56
    /**
57
     * Checks whether the current environment type in the list
58
     * of allowed ones
59
     *
60
     * @param HTTPRequest $request
61
     *
62
     * @return bool
63
     */
64
    public function checkRequestForBypass(HTTPRequest $request)
65
    {
66
        return in_array(Director::get_environment_type(), $this->environments, true);
67
    }
68
}
69