1 | <?php |
||
9 | class Config implements TransformerInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $transformers = []; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $merged = []; |
||
20 | |||
21 | /** |
||
22 | * This takes a list of transformaers which are responsible for fetching and tranforming |
||
23 | * their config into PHP array. |
||
24 | * |
||
25 | * @param TransformerInterface $transformers |
||
26 | */ |
||
27 | 1 | public function __construct(...$transformers) |
|
31 | |||
32 | /** |
||
33 | * This loops through each transformer and trnasforms the config into the common php |
||
34 | * array format. |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | 1 | public function transform() |
|
57 | |||
58 | /** |
||
59 | * This is responsible for calling each transformer and then creating an unmerged |
||
60 | * config array in blocks ordered by sort key. |
||
61 | * |
||
62 | * @example |
||
63 | * The unmerged config looks as follows: |
||
64 | * array( |
||
65 | * 10 => array(...) |
||
66 | * ); |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 1 | protected function transformAndSort() |
|
83 | |||
84 | /** |
||
85 | * This method takes a config block with a key which is used to sort. Its merged into |
||
86 | * the existing config cleanly. If the sort key exists, then we will attempt to merge |
||
87 | * that config block. If there are any key clashes at this stage, then we will throw an |
||
88 | * exception. |
||
89 | * |
||
90 | * @example |
||
91 | * $mine = array( |
||
92 | * 10 => array(...) |
||
93 | * ); |
||
94 | * |
||
95 | * $theirs = array( |
||
96 | * 5 => array(...) |
||
97 | * 15 => array(...) |
||
98 | * ); |
||
99 | * |
||
100 | * In this example, $mine would be placed in between the 5 and 15 sort keys. |
||
101 | * $return = array( |
||
102 | * 5 => array(...) |
||
103 | * 10 => array(...) |
||
104 | * 15 => array(...) |
||
105 | * ); |
||
106 | * |
||
107 | * @param array $mine |
||
108 | * @param array $theirs |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | 1 | protected function sortConfigBlocks($mine, $theirs) |
|
134 | |||
135 | /** |
||
136 | * This will merge config blocks, but throw an exception if there is a key clash. |
||
137 | * |
||
138 | * @param array $mine |
||
139 | * @param array $theirs |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | protected function mergeUniqueKeys($mine, $theirs) |
||
147 | |||
148 | /** |
||
149 | * This will merge by priority order and overwrite any existing values that aren't arrays |
||
150 | * or try to merge values that are arrays recursively. |
||
151 | * |
||
152 | * @param array $mine |
||
153 | * @param array $theirs |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | 1 | protected function mergeByPriority($mine, $theirs = []) |
|
174 | } |
||
175 |