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\controllers; |
13
|
|
|
|
14
|
|
|
use hidev\base\File; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\base\InvalidParamException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Start goal. |
20
|
|
|
* Chdirs to the project's root directory and loads dependencies and configs. |
21
|
|
|
*/ |
22
|
|
|
class StartController extends CommonController |
23
|
|
|
{ |
24
|
|
|
const MAIN_CONFIG = '.hidev/config.yml'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string absolute path to the project root directory |
28
|
|
|
*/ |
29
|
|
|
public $prjdir; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool hidev already started flag |
33
|
|
|
*/ |
34
|
|
|
public static $started = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Make action. |
38
|
|
|
*/ |
39
|
|
|
public function actionMake() |
40
|
|
|
{ |
41
|
|
|
$this->takeConfig()->includeConfig(static::MAIN_CONFIG); |
42
|
|
|
$this->addAliases(); |
43
|
|
|
$this->requireAll(); |
44
|
|
|
$this->includeAll(); |
45
|
|
|
self::$started = true; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Update action. |
50
|
|
|
* @return int exit code |
51
|
|
|
*/ |
52
|
|
|
public function actionUpdate() |
53
|
|
|
{ |
54
|
|
|
return $this->passthru('composer', ['update', '-d', '.hidev', '--prefer-source', '--ansi']); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Adds aliases: |
59
|
|
|
* - @prjdir alias to current project root dir |
60
|
|
|
* - current package namespace for it could be used from hidev. |
61
|
|
|
*/ |
62
|
|
|
public function addAliases() |
63
|
|
|
{ |
64
|
|
|
Yii::setAlias('@prjdir', $this->findPrjDir()); |
65
|
|
|
$config = $this->takeConfig()->rawItem('package'); |
66
|
|
|
$alias = '@' . strtr($config['namespace'], '\\', '/'); |
67
|
|
|
if ($alias && !Yii::getAlias($alias, false)) { |
68
|
|
|
$srcdir = Yii::getAlias('@prjdir/' . ($config['src'] ?: 'src')); |
69
|
|
|
Yii::setAlias($alias, $srcdir); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Require all configured requires. |
75
|
|
|
*/ |
76
|
|
|
protected function requireAll() |
77
|
|
|
{ |
78
|
|
|
$require = $this->takeConfig()->rawItem('require'); |
79
|
|
|
if ($require) { |
80
|
|
|
$require['hiqdev/composer-extension-plugin'] = '*@dev'; |
81
|
|
|
$saved = File::create('.hidev/composer.json')->save(compact('require')); |
82
|
|
|
if ($saved || !is_dir('.hidev/vendor')) { |
83
|
|
|
$this->runAction('update'); |
84
|
|
|
} |
85
|
|
|
/// backup config then reset with extra config then restore |
86
|
|
|
$config = $this->takeConfig()->getItems(); |
87
|
|
|
Yii::$app->clear('config'); |
88
|
|
|
Yii::$app->loadExtraVendor('.hidev/vendor'); |
89
|
|
|
$this->takeConfig()->mergeItems($config); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Include all configs. |
95
|
|
|
*/ |
96
|
|
|
public function includeAll() |
97
|
|
|
{ |
98
|
|
|
$still = true; |
99
|
|
|
while ($still) { |
100
|
|
|
$still = false; |
101
|
|
|
$include = $this->takeConfig()->rawItem('include'); |
102
|
|
|
if ($include) { |
103
|
|
|
foreach ($include as $path) { |
104
|
|
|
$still = $still || $this->takeConfig()->includeConfig($path); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Chdirs to project's root by looking for config file in the current directory and up. |
112
|
|
|
* @throws InvalidParamException when failed to find |
113
|
|
|
* @return string path to the root directory of hidev project |
114
|
|
|
*/ |
115
|
|
|
protected function findPrjDir() |
116
|
|
|
{ |
117
|
|
|
$configDir = '.hidev'; |
118
|
|
|
for ($i = 0;$i < 9;++$i) { |
119
|
|
|
if (is_dir($configDir)) { |
120
|
|
|
$this->prjdir = getcwd(); |
121
|
|
|
return $this->prjdir; |
122
|
|
|
} |
123
|
|
|
chdir('..'); |
124
|
|
|
} |
125
|
|
|
throw new InvalidParamException("Not a hidev project (or any of the parent directories).\nUse `hidev init` to initialize hidev project."); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: