|
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 getConfig(ConfigInterface $config, $key, $default = null) |
|
35
|
|
|
{ |
|
36
|
|
|
throw new \Exception('getConfig is deprecated, and not supported in SiteAliasWithConfig (which replaces it). Use "get".'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function name() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->siteAlias()->name(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritdoc |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setName($name) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->changesProhibited(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function has($key) |
|
59
|
|
|
{ |
|
60
|
|
|
return |
|
61
|
|
|
$this->runtimeConfig->has($key) || |
|
62
|
|
|
$this->siteAlias->has($key) || |
|
63
|
|
|
$this->defaultConfig->has($key); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @inheritdoc |
|
68
|
|
|
*/ |
|
69
|
|
|
public function get($key, $defaultFallback = null) |
|
70
|
|
|
{ |
|
71
|
|
|
if ($this->runtimeConfig->has($key)) { |
|
72
|
|
|
return $this->runtimeConfig->get($key); |
|
73
|
|
|
} |
|
74
|
|
|
if ($this->siteAlias->has($key)) { |
|
75
|
|
|
return $this->siteAlias->get($key); |
|
76
|
|
|
} |
|
77
|
|
|
if ($this->defaultConfig->has($key)) { |
|
78
|
|
|
return $this->defaultConfig->get($key); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $defaultFallback; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @inheritdoc |
|
86
|
|
|
*/ |
|
87
|
|
|
public function set($key, $value) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->changesProhibited(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
|
|
public function import($data) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->changesProhibited(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritdoc |
|
102
|
|
|
*/ |
|
103
|
|
|
public function replace($data) |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
|
|
$this->changesProhibited(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritdoc |
|
110
|
|
|
*/ |
|
111
|
|
|
public function combine($data) |
|
|
|
|
|
|
112
|
|
|
{ |
|
113
|
|
|
$this->changesProhibited(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Export all configuration as a nested array. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function export() |
|
120
|
|
|
{ |
|
121
|
|
|
throw new \Exception('SiteAliasWithConfig::export() not supported.'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @inheritdoc |
|
126
|
|
|
*/ |
|
127
|
|
|
public function hasDefault($key) |
|
128
|
|
|
{ |
|
129
|
|
|
return false; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @inheritdoc |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getDefault($key, $defaultFallback = null) |
|
136
|
|
|
{ |
|
137
|
|
|
return $defaultFallback; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @inheritdoc |
|
142
|
|
|
*/ |
|
143
|
|
|
public function setDefault($key, $value) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->changesProhibited(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @inheritdoc |
|
150
|
|
|
*/ |
|
151
|
|
|
public function exportConfig() |
|
152
|
|
|
{ |
|
153
|
|
|
throw new \Exception('SiteAliasWithConfig::exportConfig() not supported.'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
protected function changesProhibited() |
|
157
|
|
|
{ |
|
158
|
|
|
throw new \Exception('Changing a SiteAliasWithConfig is not permitted.'); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.