|
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-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\base; |
|
13
|
|
|
|
|
14
|
|
|
use Yii; |
|
15
|
|
|
|
|
16
|
|
|
class BinaryPhp extends Binary |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string package full name, e.g. fabpot/php-cs-fixer |
|
20
|
|
|
*/ |
|
21
|
|
|
public $package; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string package version constraint, e.g. ^1.1 |
|
25
|
|
|
*/ |
|
26
|
|
|
public $version; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string installer URL |
|
30
|
|
|
*/ |
|
31
|
|
|
public $installer; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string URL to download PHAR |
|
35
|
|
|
*/ |
|
36
|
|
|
public $download; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Detects how to run the binary. |
|
40
|
|
|
* Searches in this order: |
|
41
|
|
|
* 1. PHAR in project's root directory |
|
42
|
|
|
* 2. projects's vendor/bin directory |
|
43
|
|
|
* 3. composer global vendor/bin directory. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $name |
|
46
|
|
|
* @return string path to the binary |
|
47
|
|
|
*/ |
|
48
|
|
|
public function detectPath($name) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$paths = [Yii::getAlias("@prjdir/$name.phar"), Yii::getAlias("@prjdir/vendor/bin/$name"), "$_SERVER[HOME]/.composer/vendor/bin/$name"]; |
|
51
|
|
|
foreach ($paths as $path) { |
|
52
|
|
|
if (file_exists($path)) { |
|
53
|
|
|
return $path; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return parent::detectPath($name); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function detectCommand($path) |
|
61
|
|
|
{ |
|
62
|
|
|
$path = parent::detectCommand($path); |
|
63
|
|
|
|
|
64
|
|
|
return is_executable($path) ? $path : '/usr/bin/env php ' . $path; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function install() |
|
68
|
|
|
{ |
|
69
|
|
|
if ($this->installer) { |
|
70
|
|
|
passthru('/usr/bin/env wget ' . escapeshellarg($this->installer) . ' -O- | /usr/bin/env php', $exitcode); |
|
71
|
|
|
} elseif ($this->download) { |
|
72
|
|
|
$dest = Yii::getAlias('@prjdir/' . $this->name . '.phar'); |
|
73
|
|
|
passthru('/usr/bin/env wget ' . escapeshellarg($this->download) . ' -O ' . $dest, $exitcode); |
|
74
|
|
|
} else { |
|
75
|
|
|
return parent::install(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $exitcode; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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: