1
|
|
|
<?php |
2
|
|
|
namespace Consolidation\SiteAlias; |
3
|
|
|
|
4
|
|
|
use Consolidation\Config\ConfigInterface; |
5
|
|
|
use Consolidation\SiteAlias\AliasRecord; |
6
|
|
|
use Consolidation\SiteAlias\AliasRecordInterface; |
7
|
|
|
use Consolidation\SiteAlias\AliasRecordTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* SiteAliasWithConfig delegates to a site alias, and |
11
|
|
|
* also combines it with two config stores: |
12
|
|
|
* |
13
|
|
|
* - Runtime config (set on commandline): Options that override site alias contents |
14
|
|
|
* - Default config (set from config files): Default options |
15
|
|
|
*/ |
16
|
|
|
class SiteAliasWithConfig implements AliasRecordInterface |
17
|
|
|
{ |
18
|
|
|
use AliasRecordTrait; |
19
|
|
|
|
20
|
|
|
protected $runtimeConfig; |
21
|
|
|
protected $siteAlias; |
22
|
|
|
protected $defaultConfig; |
23
|
|
|
|
24
|
|
|
public function __construct(ConfigInterface $runtimeConfig, AliasRecordInterface $siteAlias, ConfigInterface $defaultConfig) |
25
|
|
|
{ |
26
|
|
|
$this->runtimeConfig = $runtimeConfig; |
27
|
|
|
$this->siteAlias = $siteAlias; |
28
|
|
|
$this->defaultConfig = $defaultConfig; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
34
|
|
|
public function name() |
35
|
|
|
{ |
36
|
|
|
return $this->siteAlias->name(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
|
|
public function setName($name) |
43
|
|
|
{ |
44
|
|
|
$this->changesProhibited(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritdoc |
49
|
|
|
*/ |
50
|
|
|
public function has($key) |
51
|
|
|
{ |
52
|
|
|
return |
53
|
|
|
$this->runtimeConfig->has($key) || |
54
|
|
|
$this->siteAlias->has($key) || |
55
|
|
|
$this->defaultConfig->has($key); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
|
public function get($key, $defaultFallback = null) |
62
|
|
|
{ |
63
|
|
|
if ($this->runtimeConfig->has($key)) { |
64
|
|
|
return $this->runtimeConfig->get($key); |
65
|
|
|
} |
66
|
|
|
if ($this->siteAlias->has($key)) { |
67
|
|
|
return $this->siteAlias->get($key); |
68
|
|
|
} |
69
|
|
|
if ($this->defaultConfig->has($key)) { |
70
|
|
|
return $this->defaultConfig->get($key); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $defaultFallback; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
|
|
public function set($key, $value) |
80
|
|
|
{ |
81
|
|
|
$this->changesProhibited(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
|
|
public function import($data) |
88
|
|
|
{ |
89
|
|
|
$this->changesProhibited(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritdoc |
94
|
|
|
*/ |
95
|
|
|
public function replace($data) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$this->changesProhibited(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
|
|
public function combine($data) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$this->changesProhibited(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Export all configuration as a nested array. |
110
|
|
|
*/ |
111
|
|
|
public function export() |
112
|
|
|
{ |
113
|
|
|
throw new \Exception('SiteAliasWithConfig::export() not supported.'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @inheritdoc |
118
|
|
|
*/ |
119
|
|
|
public function hasDefault($key) |
120
|
|
|
{ |
121
|
|
|
return false; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @inheritdoc |
126
|
|
|
*/ |
127
|
|
|
public function getDefault($key, $defaultFallback = null) |
128
|
|
|
{ |
129
|
|
|
return $defaultFallback; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @inheritdoc |
134
|
|
|
*/ |
135
|
|
|
public function setDefault($key, $value) |
136
|
|
|
{ |
137
|
|
|
$this->changesProhibited(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @inheritdoc |
142
|
|
|
*/ |
143
|
|
|
public function exportConfig() |
144
|
|
|
{ |
145
|
|
|
throw new \Exception('SiteAliasWithConfig::exportConfig() not supported.'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
protected function changesProhibited() |
149
|
|
|
{ |
150
|
|
|
throw new \Exception('Changing a SiteAliasWithConfig is not permitted.'); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.