Skip to content

Commit

Permalink
refactor(util.executable): use ahc/cli/shell and findBinary
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Sep 23, 2018
1 parent 56747a3 commit b51feee
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Util/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Ahc\Phint\Util;

use Ahc\Cli\Helper\Shell;
use Ahc\Cli\IO\Interactor;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
Expand All @@ -36,7 +37,7 @@ public function __construct($binary = null, string $logFile = '')
{
$this->workDir = \getcwd();
$this->logFile = $logFile;
$this->binary = $binary ? '"' . $binary . '"' : $this->binary;
$this->binary = $this->findBinary($binary ?? $this->binary);
}

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

protected function findBinary($binary)
protected function findBinary(string $binary)
{
if (\is_executable($binary)) {
return $binary;
Expand All @@ -75,17 +76,13 @@ protected function findBinary($binary)
*/
protected function runCommand($command)
{
$proc = new Process($this->binary . ' ' . $command, $this->workDir, null, null, null);
$proc = new Shell($this->binary . ' ' . $command);

$pathUtil = new Path;
$proc->setOptions($this->workDir)->execute();

$proc->run(function ($type, $data) use ($pathUtil) {
if ($this->logFile) {
$pathUtil->writeFile($this->logFile, $data, \FILE_APPEND);
}
});
(new Path)->writeFile($this->logFile, $proc->getErrorOutput(), \FILE_APPEND);

$this->isSuccessful = $proc->isSuccessful();
$this->isSuccessful = 0 === $proc->getExitCode();

return $proc->getOutput();
}
Expand Down

0 comments on commit b51feee

Please sign in to comment.