Create a "isTtySupported" static method

This commit is contained in:
Johann Pardanaud 2017-11-24 11:13:34 +01:00
parent cfdc145dab
commit a1398f6de4

View File

@ -976,16 +976,9 @@ class Process implements \IteratorAggregate
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
throw new RuntimeException('TTY mode is not supported on Windows platform.');
}
if ($tty) {
static $isTtySupported;
if (null === $isTtySupported) {
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
}
if (!$isTtySupported) {
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
}
if ($tty && !self::isTtySupported()) {
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
}
$this->tty = (bool) $tty;
@ -1169,6 +1162,22 @@ class Process implements \IteratorAggregate
}
}
/**
* Returns whether TTY is supported on the current operating system.
*
* @return bool
*/
public static function isTtySupported()
{
static $isTtySupported;
if (null === $isTtySupported) {
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
}
return $isTtySupported;
}
/**
* Returns whether PTY is supported on the current operating system.
*