Replace STDIN by php://stdin

This commit is contained in:
Nicolas Grekas 2019-10-17 14:23:42 +02:00
parent cbc4efc345
commit 365d02be77
4 changed files with 7 additions and 37 deletions

View File

@ -81,7 +81,7 @@ EOF
$showDeprecations = $input->getOption('show-deprecations');
if (['-'] === $filenames) {
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), uniqid('sf_', true))]);
}
if (!$filenames) {
@ -89,7 +89,7 @@ EOF
if (0 === ftell(STDIN)) {
@trigger_error('Piping content from STDIN to the "lint:twig" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), uniqid('sf_', true))]);
}
$loader = $this->twig->getLoader();
@ -132,16 +132,6 @@ EOF
return $this->display($input, $output, $io, $filesInfo);
}
private function getStdin(): string
{
$template = '';
while (!feof(STDIN)) {
$template .= fread(STDIN, 1024);
}
return $template;
}
private function getFilesInfo(array $filenames): array
{
$filesInfo = [];

View File

@ -115,7 +115,7 @@ class QuestionHelper extends Helper
{
$this->writePrompt($output, $question);
$inputStream = $this->inputStream ?: STDIN;
$inputStream = $this->inputStream ?: fopen('php://stdin', 'r');
$autocomplete = $question->getAutocompleterCallback();
if (null === $autocomplete || !Terminal::hasSttyAvailable()) {

View File

@ -85,7 +85,7 @@ EOF
$this->displayCorrectFiles = $output->isVerbose();
if (['-'] === $filenames) {
return $this->display($io, [$this->validate($this->getStdin())]);
return $this->display($io, [$this->validate(file_get_contents('php://stdin'))]);
}
// @deprecated to be removed in 5.0
@ -96,7 +96,7 @@ EOF
@trigger_error('Piping content from STDIN to the "lint:xliff" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
return $this->display($io, [$this->validate($this->getStdin())]);
return $this->display($io, [$this->validate(file_get_contents('php://stdin'))]);
}
$filesInfo = [];
@ -230,16 +230,6 @@ EOF
}
}
private function getStdin(): string
{
$xliff = '';
while (!feof(STDIN)) {
$xliff .= fread(STDIN, 1024);
}
return $xliff;
}
private function getDirectoryIterator(string $directory)
{
$default = function ($directory) {

View File

@ -88,7 +88,7 @@ EOF
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
if (['-'] === $filenames) {
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
}
// @deprecated to be removed in 5.0
@ -96,7 +96,7 @@ EOF
if (0 === ftell(STDIN)) {
@trigger_error('Piping content from STDIN to the "lint:yaml" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
}
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
@ -215,16 +215,6 @@ EOF
}
}
private function getStdin(): string
{
$yaml = '';
while (!feof(STDIN)) {
$yaml .= fread(STDIN, 1024);
}
return $yaml;
}
private function getParser(): Parser
{
if (!$this->parser) {