Skip to content

Commit a1398f6

Browse files
committed
Create a "isTtySupported" static method
1 parent cfdc145 commit a1398f6

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -976,16 +976,9 @@ public function setTty($tty)
976976
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
977977
throw new RuntimeException('TTY mode is not supported on Windows platform.');
978978
}
979-
if ($tty) {
980-
static $isTtySupported;
981979

982-
if (null === $isTtySupported) {
983-
$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);
984-
}
985-
986-
if (!$isTtySupported) {
987-
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
988-
}
980+
if ($tty && !self::isTtySupported()) {
981+
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
989982
}
990983

991984
$this->tty = (bool) $tty;
@@ -1169,6 +1162,22 @@ public function checkTimeout()
11691162
}
11701163
}
11711164

1165+
/**
1166+
* Returns whether TTY is supported on the current operating system.
1167+
*
1168+
* @return bool
1169+
*/
1170+
public static function isTtySupported()
1171+
{
1172+
static $isTtySupported;
1173+
1174+
if (null === $isTtySupported) {
1175+
$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);
1176+
}
1177+
1178+
return $isTtySupported;
1179+
}
1180+
11721181
/**
11731182
* Returns whether PTY is supported on the current operating system.
11741183
*

0 commit comments

Comments
 (0)