forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorConfigStackSource.php
80 lines (67 loc) · 1.74 KB
/
PhabricatorConfigStackSource.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
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Configuration source which reads from a stack of other configuration
* sources.
*
* This source is writable if any source in the stack is writable. Writes happen
* to the first writable source only.
*/
final class PhabricatorConfigStackSource
extends PhabricatorConfigSource {
private $stack = array();
public function pushSource(PhabricatorConfigSource $source) {
array_unshift($this->stack, $source);
return $this;
}
public function popSource() {
if (empty($this->stack)) {
throw new Exception(pht('Popping an empty %s!', __CLASS__));
}
return array_shift($this->stack);
}
public function getStack() {
return $this->stack;
}
public function getKeys(array $keys) {
$result = array();
foreach ($this->stack as $source) {
$result = $result + $source->getKeys($keys);
}
return $result;
}
public function getAllKeys() {
$result = array();
foreach ($this->stack as $source) {
$result = $result + $source->getAllKeys();
}
return $result;
}
public function canWrite() {
foreach ($this->stack as $source) {
if ($source->canWrite()) {
return true;
}
}
return false;
}
public function setKeys(array $keys) {
foreach ($this->stack as $source) {
if ($source->canWrite()) {
$source->setKeys($keys);
return;
}
}
// We can't write; this will throw an appropriate exception.
parent::setKeys($keys);
}
public function deleteKeys(array $keys) {
foreach ($this->stack as $source) {
if ($source->canWrite()) {
$source->deleteKeys($keys);
return;
}
}
// We can't write; this will throw an appropriate exception.
parent::deleteKeys($keys);
}
}