1 | <?php |
||
21 | class Builder |
||
22 | { |
||
23 | /** |
||
24 | * @var string path to output assembled configs |
||
25 | */ |
||
26 | protected $outputDir; |
||
27 | |||
28 | /** |
||
29 | * @var array files to build configs |
||
30 | * @see buildConfigs() |
||
31 | */ |
||
32 | protected $files = []; |
||
33 | |||
34 | /** |
||
35 | * @var array additional data to be merged into every config (e.g. aliases) |
||
36 | */ |
||
37 | protected $addition = []; |
||
38 | |||
39 | /** |
||
40 | * @var IOInterface |
||
41 | */ |
||
42 | protected $io; |
||
43 | |||
44 | /** |
||
45 | * @var array collected variables |
||
46 | */ |
||
47 | protected $vars = []; |
||
48 | |||
49 | const OUTPUT_DIR_SUFFIX = '-output'; |
||
50 | const BASE_DIR_MARKER = '<<<base-dir>>>'; |
||
51 | |||
52 | public function __construct(array $files = [], $outputDir = null) |
||
57 | |||
58 | public function setFiles(array $files) |
||
62 | |||
63 | public function setOutputDir($outputDir) |
||
67 | |||
68 | public function setAddition(array $addition) |
||
72 | |||
73 | public function loadFiles() |
||
78 | |||
79 | public function saveFiles() |
||
84 | |||
85 | public static function rebuild($outputDir) |
||
91 | |||
92 | /** |
||
93 | * Returns default output dir. |
||
94 | * @return string |
||
95 | */ |
||
96 | public static function defaultOutputDir() |
||
100 | |||
101 | /** |
||
102 | * Returns full path to assembled config file. |
||
103 | * @param string $filename name of config |
||
104 | * @return string absolute path |
||
105 | */ |
||
106 | public static function path($filename) |
||
110 | |||
111 | /** |
||
112 | * Builds configs by given files list |
||
113 | * @param null|array $files files to process: config name => list of files |
||
114 | */ |
||
115 | 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 | * Substitute all pathes in given array recursively with alias if applicable. |
||
182 | * @param array $data |
||
183 | * @param string $dir |
||
184 | * @param string $alias |
||
185 | * @return string |
||
186 | */ |
||
187 | public static function substitutePathes($data, $dir, $alias) |
||
199 | |||
200 | /** |
||
201 | * Substitute path with alias if applicable. |
||
202 | * @param string $path |
||
203 | * @param string $dir |
||
204 | * @param string $alias |
||
205 | * @return string |
||
206 | */ |
||
207 | protected static function substitutePath($path, $dir, $alias) |
||
211 | |||
212 | public function readConfig($name) |
||
216 | |||
217 | /** |
||
218 | * Reads config file. |
||
219 | * @param string $__path |
||
220 | * @return array configuration read from file |
||
221 | */ |
||
222 | public function readFile($__path) |
||
242 | |||
243 | public function setIo(IOInterface $io) |
||
247 | |||
248 | protected function writeError($text) |
||
256 | } |
||
257 |