|
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) 2014-2015, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\goals; |
|
13
|
|
|
|
|
14
|
|
|
use Yii; |
|
15
|
|
|
use yii\base\InvalidConfigException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Install goal. |
|
19
|
|
|
*/ |
|
20
|
|
|
class InstallGoal extends DefaultGoal |
|
21
|
|
|
{ |
|
22
|
|
|
public function actionMake() |
|
23
|
|
|
{ |
|
24
|
|
|
Yii::warning('install'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function actionUpdate() |
|
28
|
|
|
{ |
|
29
|
|
|
exec('cd .hidev;composer update --prefer-source'); |
|
30
|
|
|
$this->module->runRequest(''); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected $_bins; |
|
34
|
|
|
|
|
35
|
|
|
public function getBin($prog) |
|
36
|
|
|
{ |
|
37
|
|
|
if ($this->_bins[$prog] === null) { |
|
38
|
|
|
$this->_bins[$prog] = $this->detectBin($prog); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $this->_bins[$prog]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Detects how to run given prog. |
|
46
|
|
|
* Searches in this order: |
|
47
|
|
|
* 1. prog.phar in project root directory |
|
48
|
|
|
* 2. ./vendor/bin/prog |
|
49
|
|
|
* 3. $HOME/.composer/vendor/bin/prog |
|
50
|
|
|
* 4. `which $prog`. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $prog |
|
53
|
|
|
* @return string path to the binary prepended with `env php` when found file is not executable |
|
54
|
|
|
*/ |
|
55
|
|
|
public function detectBin($prog) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
/* |
|
|
|
|
|
|
58
|
|
|
$pkg = $this->getItem('bin')[$prog]; |
|
59
|
|
|
if (!$pkg) { |
|
60
|
|
|
throw new InvalidConfigException("Unknown bin: $prog"); |
|
61
|
|
|
} |
|
62
|
|
|
$path = $this->package->hasRequireAny($pkg) ? './vendor/bin' : '$HOME/.composer/vendor/bin'; |
|
63
|
|
|
*/ |
|
64
|
|
|
|
|
65
|
|
|
$paths = [Yii::getAlias("@source/$prog.phar"), Yii::getAlias("@source/vendor/bin/$prog"), "$_SERVER[HOME]/.composer/vendor/bin/$prog"]; |
|
66
|
|
|
foreach ($paths as $path) { |
|
67
|
|
|
if (file_exists($path)) { |
|
68
|
|
|
return is_executable($path) ? $path : 'env php ' . $path; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$path = exec('which ' . $prog); |
|
73
|
|
|
if ($path) { |
|
74
|
|
|
return $prog; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
throw new InvalidConfigException("Failed to find how to run $prog"); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: