Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses #131. Added check to see if TTY is available. #135

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DrupalCheck\Command;

use DrupalCheck\Util\Tty;
use DrupalFinder\DrupalFinder;
use Nette\Neon\Neon;
use PHPStan\ShouldNotHappenException;
Expand Down Expand Up @@ -211,7 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$command = array_merge($command, $paths);

$process = new Process($command);
$process->setTty(true);
$process->setTty(Tty::isTtySupported());
$process->setTimeout(null);
$process->run(static function ($type, $buffer) use ($output) {
if (Process::ERR === $type) {
Expand Down
28 changes: 28 additions & 0 deletions src/Util/Tty.php
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);
}
}