11
11
12
12
namespace Ahc \Phint \Util ;
13
13
14
+ use Ahc \Cli \Helper \Shell ;
14
15
use Ahc \Cli \IO \Interactor ;
15
16
use Symfony \Component \Process \ExecutableFinder ;
16
17
use Symfony \Component \Process \Process ;
@@ -36,7 +37,7 @@ public function __construct($binary = null, string $logFile = '')
36
37
{
37
38
$ this ->workDir = \getcwd ();
38
39
$ this ->logFile = $ logFile ;
39
- $ this ->binary = $ binary ? ' " ' . $ binary . ' " ' : $ this ->binary ;
40
+ $ this ->binary = $ this -> findBinary ( $ binary ?? $ this ->binary ) ;
40
41
}
41
42
42
43
public function withWorkDir ($ workDir = null )
@@ -55,7 +56,7 @@ public function successful(): bool
55
56
return $ this ->isSuccessful ;
56
57
}
57
58
58
- protected function findBinary ($ binary )
59
+ protected function findBinary (string $ binary )
59
60
{
60
61
if (\is_executable ($ binary )) {
61
62
return $ binary ;
@@ -75,17 +76,13 @@ protected function findBinary($binary)
75
76
*/
76
77
protected function runCommand ($ command )
77
78
{
78
- $ proc = new Process ($ this ->binary . ' ' . $ command, $ this -> workDir , null , null , null );
79
+ $ proc = new Shell ($ this ->binary . ' ' . $ command );
79
80
80
- $ pathUtil = new Path ;
81
+ $ proc -> setOptions ( $ this -> workDir )-> execute () ;
81
82
82
- $ proc ->run (function ($ type , $ data ) use ($ pathUtil ) {
83
- if ($ this ->logFile ) {
84
- $ pathUtil ->writeFile ($ this ->logFile , $ data , \FILE_APPEND );
85
- }
86
- });
83
+ (new Path )->writeFile ($ this ->logFile , $ proc ->getErrorOutput (), \FILE_APPEND );
87
84
88
- $ this ->isSuccessful = $ proc ->isSuccessful ();
85
+ $ this ->isSuccessful = 0 === $ proc ->getExitCode ();
89
86
90
87
return $ proc ->getOutput ();
91
88
}
0 commit comments