Skip to content

Commit b51feee

Browse files
committed
refactor(util.executable): use ahc/cli/shell and findBinary
1 parent 56747a3 commit b51feee

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Util/Executable.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Ahc\Phint\Util;
1313

14+
use Ahc\Cli\Helper\Shell;
1415
use Ahc\Cli\IO\Interactor;
1516
use Symfony\Component\Process\ExecutableFinder;
1617
use Symfony\Component\Process\Process;
@@ -36,7 +37,7 @@ public function __construct($binary = null, string $logFile = '')
3637
{
3738
$this->workDir = \getcwd();
3839
$this->logFile = $logFile;
39-
$this->binary = $binary ? '"' . $binary . '"' : $this->binary;
40+
$this->binary = $this->findBinary($binary ?? $this->binary);
4041
}
4142

4243
public function withWorkDir($workDir = null)
@@ -55,7 +56,7 @@ public function successful(): bool
5556
return $this->isSuccessful;
5657
}
5758

58-
protected function findBinary($binary)
59+
protected function findBinary(string $binary)
5960
{
6061
if (\is_executable($binary)) {
6162
return $binary;
@@ -75,17 +76,13 @@ protected function findBinary($binary)
7576
*/
7677
protected function runCommand($command)
7778
{
78-
$proc = new Process($this->binary . ' ' . $command, $this->workDir, null, null, null);
79+
$proc = new Shell($this->binary . ' ' . $command);
7980

80-
$pathUtil = new Path;
81+
$proc->setOptions($this->workDir)->execute();
8182

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);
8784

88-
$this->isSuccessful = $proc->isSuccessful();
85+
$this->isSuccessful = 0 === $proc->getExitCode();
8986

9087
return $proc->getOutput();
9188
}

0 commit comments

Comments
 (0)