1 | <?php |
||
20 | class Builder |
||
21 | { |
||
22 | /** |
||
23 | * @var string path to output assembled configs |
||
24 | */ |
||
25 | protected $outputDir; |
||
26 | |||
27 | /** |
||
28 | * @var array files to build configs |
||
29 | * @see buildConfigs() |
||
30 | */ |
||
31 | protected $files = []; |
||
32 | |||
33 | /** |
||
34 | * @var array additional data to be merged into every config (e.g. aliases) |
||
35 | */ |
||
36 | protected $addition = []; |
||
37 | |||
38 | /** |
||
39 | * @var IOInterface |
||
40 | */ |
||
41 | protected $io; |
||
42 | |||
43 | /** |
||
44 | * @var array collected variables |
||
45 | */ |
||
46 | protected $vars = []; |
||
47 | |||
48 | const OUTPUT_DIR_SUFFIX = '-output'; |
||
49 | const BASE_DIR_MARKER = '<<<base-dir>>>'; |
||
50 | |||
51 | public function __construct(array $files = [], $outputDir = null) |
||
56 | |||
57 | public function setFiles(array $files) |
||
61 | |||
62 | public function setOutputDir($outputDir) |
||
66 | |||
67 | public function setAddition(array $addition) |
||
71 | |||
72 | public function loadFiles() |
||
77 | |||
78 | public function saveFiles() |
||
83 | |||
84 | public static function rebuild($outputDir) |
||
90 | |||
91 | /** |
||
92 | * Returns default output dir. |
||
93 | * @return string |
||
94 | */ |
||
95 | public static function defaultOutputDir() |
||
99 | |||
100 | /** |
||
101 | * Returns full path to assembled config file. |
||
102 | * @param string $filename name of config |
||
103 | * @return string absolute path |
||
104 | */ |
||
105 | public static function path($filename) |
||
109 | |||
110 | /** |
||
111 | * Builds configs by given files list. |
||
112 | * @param null|array $files files to process: config name => list of files |
||
113 | */ |
||
114 | public function buildConfigs($files = null) |
||
128 | |||
129 | /** |
||
130 | * Merges given configs and writes at given name. |
||
131 | * @param mixed $name |
||
132 | * @param array $configs |
||
133 | */ |
||
134 | public function buildConfig($name, array $configs) |
||
144 | |||
145 | protected function isSpecialConfig($name) |
||
149 | |||
150 | /** |
||
151 | * Writes config file by name. |
||
152 | * @param string $name |
||
153 | * @param array $data |
||
154 | */ |
||
155 | public function writeConfig($name, array $data) |
||
160 | |||
161 | public function getOutputPath($name) |
||
165 | |||
166 | /** |
||
167 | * Writes config file by full path. |
||
168 | * @param string $path |
||
169 | * @param array $data |
||
170 | */ |
||
171 | public static function writeFile($path, array $data) |
||
179 | |||
180 | /** |
||
181 | * Writes file if content changed. |
||
182 | * @param string $path |
||
183 | * @param string $content |
||
184 | */ |
||
185 | public static function putFile($path, $content) |
||
191 | |||
192 | /** |
||
193 | * Substitute all pathes in given array recursively with alias if applicable. |
||
194 | * @param array $data |
||
195 | * @param string $dir |
||
196 | * @param string $alias |
||
197 | * @return string |
||
198 | */ |
||
199 | public static function substitutePathes($data, $dir, $alias) |
||
211 | |||
212 | /** |
||
213 | * Substitute path with alias if applicable. |
||
214 | * @param string $path |
||
215 | * @param string $dir |
||
216 | * @param string $alias |
||
217 | * @return string |
||
218 | */ |
||
219 | protected static function substitutePath($path, $dir, $alias) |
||
223 | |||
224 | public function readConfig($name) |
||
228 | |||
229 | /** |
||
230 | * Reads config file. |
||
231 | * @param string $__path |
||
232 | * @return array configuration read from file |
||
233 | */ |
||
234 | public function readFile($__path) |
||
254 | |||
255 | public function setIo(IOInterface $io) |
||
259 | |||
260 | protected function writeError($text) |
||
268 | } |
||
269 |