Completed
Pull Request — master (#1952)
by Basil
02:12
created

ConfigDefinition::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php
2
3
namespace luya;
4
5
class ConfigDefinition
6
{
7
    const GROUP_COMPONENTS = 1;
8
9
    const GROUP_MODULES = 2;
10
11
    const GROUP_APPLICATIONS = 3;
12
13
    private $_group;
14
15
    private $_key;
16
17
    private $_config = [];
18
19
    public function __construct($group, $key, $config)
20
    {
21
        $this->_group = $group;
22
        $this->_key = $key;
23
        
24
        if (empty($config)) {
25
            $config = [];
26
        }
27
28
        $this->_config = is_array($config) ? $config : ['class' => $config];
29
    }
30
31
    private $_env = Config::ENV_ALL;
32
33
    public function env($env)
34
    {
35
        $this->_env = $env;
36
37
        return $this;
38
    }
39
40
    private $_runtime = Config::RUNTIME_ALL;
41
42
    public function runtime($runtime)
43
    {
44
        $this->_runtime = $runtime;
45
46
        return $this;
47
    }
48
    
49
    public function consoleRuntime()
50
    {
51
        $this->_runtime = Config::RUNTIME_CONSOLE;
52
53
        return $this;
54
    }
55
56
    public function webRuntime()
57
    {
58
        $this->_runtime = Config::RUNTIME_WEB;
59
60
        return $this;
61
    }
62
63
    public function validateRuntime($runtime)
64
    {
65
        return $this->_runtime == $runtime;
66
    }
67
68
    public function validateEnvs(array $envs)
69
    {
70
        return in_array($this->_env, $envs);
71
72
    }
73
74
    public function getGroup()
75
    {
76
        return $this->_group;
77
    }
78
79
    public function getKey()
80
    {
81
        return $this->_key;
82
    }
83
84
    public function getConfig()
85
    {
86
        return $this->_config;
87
    }
88
}