1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Automation tool mixed with code generator for easier continuous development |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hidev |
6
|
|
|
* @package hidev |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hidev\base; |
12
|
|
|
|
13
|
|
|
use Yii; |
14
|
|
|
|
15
|
|
|
class BinaryPhp extends Binary |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Detects how to run the binary. |
19
|
|
|
* Searches in this order: |
20
|
|
|
* 1. PHAR in project's root directory |
21
|
|
|
* 2. projects's vendor/bin directory |
22
|
|
|
* 3. composer global vendor/bin directory. |
23
|
|
|
* @param string $name |
24
|
|
|
* @return string path to the binary |
25
|
|
|
*/ |
26
|
|
|
public function detectPath($name) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$paths = [Yii::getAlias("@root/$name.phar", false), Yii::getAlias("@root/vendor/bin/$name", false), "$_SERVER[HOME]/.composer/vendor/bin/$name"]; |
29
|
|
|
foreach ($paths as $path) { |
30
|
|
|
if (file_exists($path)) { |
31
|
|
|
return $path; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return parent::detectPath($name); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Detect command execution string. |
40
|
|
|
* @param mixed $path |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function detectCommand($path) |
44
|
|
|
{ |
45
|
|
|
$path = parent::detectCommand($path); |
46
|
|
|
|
47
|
|
|
return is_executable($path) ? $path : '/usr/bin/env php ' . $path; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function install() |
51
|
|
|
{ |
52
|
|
|
if ($this->installer) { |
53
|
|
|
passthru('/usr/bin/env wget ' . escapeshellarg($this->installer) . ' -O- | /usr/bin/env php', $exitcode); |
54
|
|
|
} elseif ($this->download) { |
55
|
|
|
$dest = Yii::getAlias('@root/' . $this->name . '.phar', false); |
56
|
|
|
passthru('/usr/bin/env wget ' . escapeshellarg($this->download) . ' -O ' . $dest, $exitcode); |
57
|
|
|
} else { |
58
|
|
|
return parent::install(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $exitcode; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getVcsignore() |
65
|
|
|
{ |
66
|
|
|
return $this->name . '.phar'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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: