1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
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
|
|
|
public function hasGoal($id) |
26
|
|
|
{ |
27
|
|
|
return $this->hasItem($id); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getItemConfig($id = null, array $config = []) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
if (isset($config['class']) && $this->hasItem($config['class'])) { |
33
|
|
|
$config = array_merge($config, $this->_items[$config['class']]); |
34
|
|
|
} |
35
|
|
|
return ArrayHelper::merge([ |
36
|
|
|
'class' => 'hidev\controllers\CommonController', |
37
|
|
|
], $config); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function createItem($id, $config = []) |
41
|
|
|
{ |
42
|
|
|
return Yii::createObject($this->getItemConfig($id, $config), [$id, Yii::$app]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getItem($id) |
46
|
|
|
{ |
47
|
|
|
$item = &$this->_items[$id]; |
48
|
|
|
if (is_array($item)) { |
49
|
|
|
$item = $this->createItem($id, $item); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $item; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Include config file, unique only. |
57
|
|
|
* @param string|array $path |
58
|
|
|
* @return bool true if the path was unique and loaded |
59
|
|
|
*/ |
60
|
|
|
public function includeConfig($path) |
61
|
|
|
{ |
62
|
|
|
$file = File::create($path); |
63
|
|
|
$path = $file->getPath(); |
64
|
|
|
if (!isset($this->_included[$path])) { |
65
|
|
|
$this->_included[$path] = $path; |
66
|
|
|
$this->mergeItems($file->load()); |
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getGoal($id) |
74
|
|
|
{ |
75
|
|
|
return Yii::$app->createControllerById($id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getVcs() |
79
|
|
|
{ |
80
|
|
|
/// TODO determine VCS |
81
|
|
|
return $this->getGoal('git'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.