|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Automation tool mixed with code generator for easier continuous development |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hidev |
|
7
|
|
|
* @package hidev |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\components; |
|
13
|
|
|
|
|
14
|
|
|
use hidev\base\File; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
use yii\helpers\ArrayHelper; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The Config. Keeps config and Goals. |
|
20
|
|
|
*/ |
|
21
|
|
|
class Config extends \hiqdev\yii2\collection\Object |
|
22
|
|
|
{ |
|
23
|
|
|
protected $_included = []; |
|
24
|
|
|
|
|
25
|
5 |
|
public function hasGoal($id) |
|
26
|
|
|
{ |
|
27
|
5 |
|
return $this->hasItem($id); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
5 |
|
public function getItemConfig($id = null, array $config = []) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
5 |
|
if (isset($config['class']) && $this->hasItem($config['class'])) { |
|
33
|
|
|
$config = array_merge($config, $this->_items[$config['class']]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
5 |
|
return ArrayHelper::merge([ |
|
37
|
5 |
|
'class' => 'hidev\controllers\CommonController', |
|
38
|
5 |
|
], $config); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
5 |
|
public function createItem($id, $config = []) |
|
42
|
|
|
{ |
|
43
|
5 |
|
return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
5 |
|
public function getItem($id) |
|
47
|
|
|
{ |
|
48
|
5 |
|
$item = &$this->_items[$id]; |
|
49
|
5 |
|
if (is_array($item)) { |
|
50
|
5 |
|
if (count($item) === 1 && key($item) === 'alias') { |
|
51
|
|
|
$item = $this->getItem($item['alias']); |
|
52
|
|
|
} else { |
|
53
|
5 |
|
$item = $this->createItem($id, $item); |
|
54
|
|
|
} |
|
55
|
5 |
|
} |
|
56
|
|
|
|
|
57
|
5 |
|
return $item; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Include config file, unique only. |
|
62
|
|
|
* @param string|array $path |
|
63
|
|
|
* @return bool true if the path was unique and loaded |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function includeConfig($path, $force = false) |
|
66
|
|
|
{ |
|
67
|
2 |
|
$file = File::create($path); |
|
68
|
2 |
|
$path = $file->getPath(); |
|
69
|
2 |
|
if (!isset($this->_included[$path]) || $force) { |
|
70
|
2 |
|
$this->_included[$path] = $path; |
|
71
|
2 |
|
$this->mergeItems($file->load()); |
|
72
|
|
|
|
|
73
|
2 |
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
4 |
|
public function getGoal($id) |
|
80
|
|
|
{ |
|
81
|
4 |
|
return Yii::$app->createControllerById($id); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function getVcs() |
|
85
|
|
|
{ |
|
86
|
|
|
/// TODO determine VCS |
|
87
|
2 |
|
return $this->getGoal('git'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.