1 | <?php |
||
15 | class UnitsController extends \yii\console\Controller |
||
16 | { |
||
17 | public function actionPrepare() |
||
18 | { |
||
19 | $dir = dirname(__DIR__, 2); |
||
20 | $src = "$dir/res/units-tree.yml"; |
||
21 | $tree = Yaml::parse(file_get_contents($src)); |
||
22 | $this->prepareUnits('', $tree); |
||
23 | $dump = var_export($this->units, true); |
||
24 | |||
25 | $dst = "$dir/res/units-tree.php"; |
||
26 | $old = file_get_contents($dst); |
||
27 | $new = "<?php\n\nreturn $dump;\n"; |
||
28 | if ($old !== $new) { |
||
29 | echo "Written units-tree.php\n"; |
||
30 | file_put_contents($dst, $new); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | protected $units = []; |
||
35 | |||
36 | protected function prepareUnits($parent, $units) |
||
57 | } |
||
58 |