Last active
August 29, 2015 13:59
-
-
Save tr-github/10877713 to your computer and use it in GitHub Desktop.
ShellHelper.php (cygwin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Teq\Helpers; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Process\Process; | |
class ShellHelper | |
{ | |
const CHAR_SAMELINE = "\x0D"; | |
/** | |
* Progress cursors | |
* @var array | |
*/ | |
static protected $cursors = array('-', '\\', '|', '/'); | |
/** | |
* @param $cmd | |
* @return Process | |
*/ | |
public static function run($cmd) | |
{ | |
if (static::isCygwin()) | |
{ | |
$cmd = "C:\cygwin\bin\bash.exe --login -c '" . $cmd . "'"; | |
} | |
$process = new Process($cmd); | |
$process->run(); | |
return $process; | |
} | |
public static function isCygwin() | |
{ | |
$cmd = "cygpath -w ~"; | |
$process = new Process($cmd); | |
$process->run(); | |
return $process->isSuccessful(); | |
} | |
public static function progress(OutputInterface $output) | |
{ | |
$char = current(static::$cursors); | |
$output->write(static::CHAR_SAMELINE . $char); | |
if (false === next(static::$cursors)) | |
{ | |
reset(static::$cursors); | |
} | |
} | |
public static function progressEnd(OutputInterface $output) | |
{ | |
$output->write(static::CHAR_SAMELINE . ' '); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment