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
|
|
|
public static $started = false; |
32
|
|
|
|
33
|
|
|
public function actionMake() |
34
|
|
|
{ |
35
|
|
|
Yii::setAlias('@prjdir', $this->findPrjDir()); |
36
|
|
|
$this->takeConfig()->includeConfig(static::MAIN_CONFIG); |
37
|
|
|
$this->requireAll(); |
38
|
|
|
$this->includeAll(); |
39
|
|
|
self::$started = true; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function actionUpdate() |
43
|
|
|
{ |
44
|
|
|
return $this->passthru('composer', ['update', '-d', '.hidev', '--prefer-source', '--ansi']); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function requireAll() |
48
|
|
|
{ |
49
|
|
|
$require = $this->takeConfig()->rawItem('require'); |
50
|
|
|
if ($require) { |
51
|
|
|
$require['hiqdev/composer-extension-plugin'] = '*@dev'; |
52
|
|
|
$saved = File::create('.hidev/composer.json')->save(compact('require')); |
53
|
|
|
if ($saved || !is_dir('.hidev/vendor')) { |
54
|
|
|
$this->runAction('update'); |
55
|
|
|
} |
56
|
|
|
/// backup config then reset with extra config then restore |
57
|
|
|
$config = $this->takeConfig()->getItems(); |
58
|
|
|
Yii::$app->clear('config'); |
59
|
|
|
Yii::$app->loadExtraVendor('.hidev/vendor'); |
60
|
|
|
$this->takeConfig()->mergeItems($config); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Include all configs. |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function includeAll() |
69
|
|
|
{ |
70
|
|
|
$still = true; |
71
|
|
|
while ($still) { |
72
|
|
|
$still = false; |
73
|
|
|
$include = $this->takeConfig()->rawItem('include'); |
74
|
|
|
if ($include) { |
75
|
|
|
foreach ($include as $path) { |
76
|
|
|
$still = $still || $this->takeConfig()->includeConfig($path); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Chdirs to project's root by looking for config file in the current directory and up. |
84
|
|
|
* @throws InvalidParamException when failed to find |
85
|
|
|
* @return string path to the root directory of hidev project |
86
|
|
|
*/ |
87
|
|
|
protected function findPrjDir() |
88
|
|
|
{ |
89
|
|
|
$configDir = '.hidev'; |
90
|
|
|
for ($i = 0;$i < 9;++$i) { |
91
|
|
|
if (is_dir($configDir)) { |
92
|
|
|
$this->prjdir = getcwd(); |
93
|
|
|
return $this->prjdir; |
94
|
|
|
} |
95
|
|
|
chdir('..'); |
96
|
|
|
} |
97
|
|
|
throw new InvalidParamException("Not a hidev project (or any of the parent directories).\nUse `hidev init` to initialize hidev project."); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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: