-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from joeparsons/bug/131
Addresses #131. Added check to see if TTY is available.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace DrupalCheck\Util; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Wrapper for universal support of TTY-related functionality across versions of | ||
* Symfony Process. | ||
*/ | ||
class Tty | ||
{ | ||
/** | ||
* In Symfony Process 4+, this is simply a wrapper for Process::isTtySupported(). | ||
* In lower versions, it mimics the same functionality. | ||
*/ | ||
public static function isTtySupported() | ||
{ | ||
// Start off by checking STDIN with `posix_isatty`, as that appears to be more reliable | ||
if (function_exists('posix_isatty')) { | ||
return posix_isatty(STDIN); | ||
} | ||
if (method_exists('\Symfony\Component\Process\Process', 'isTtySupported')) { | ||
return Process::isTtySupported(); | ||
} | ||
return (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes); | ||
} | ||
} |