8000 Replace STDIN by php://stdin · symfony/symfony@365d02b · GitHub
[go: up one dir, main page]

Skip to content

Commit 365d02b

Browse files
Replace STDIN by php://stdin
1 parent cbc4efc commit 365d02b

File tree

4 files changed

+7
-37
lines changed

4 files changed

+7
-37
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181
$showDeprecations = $input->getOption('show-deprecations');
8282

8383
if (['-'] === $filenames) {
84-
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
84+
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), uniqid('sf_', true))]);
8585
}
8686

8787
if (!$filenames) {
8888
// @deprecated to be removed in 5.0
8989
if (0 === ftell(STDIN)) {
9090
@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);
9191

92-
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
92+
return $this->display($input, $output, $io, [$this->validate(file_get_contents('php://stdin'), uniqid('sf_', true))]);
9393
}
9494

9595
$loader = $this->twig->getLoader();
@@ -132,16 +132,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
132132
return $this->display($input, $output, $io, $filesInfo);
133133
}
134134

135-
private function getStdin(): string
136-
{
137-
$template = '';
138-
while (!feof(STDIN)) {
139-
$template .= fread(STDIN, 1024);
140-
}
141-
142-
return $template;
143-
}
144-
145135
private function getFilesInfo(array $filenames): array
146136
{
147137
$filesInfo = [];

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private function doAsk(OutputInterface $output, Question $question)
115115
{
116116
$this->writePrompt($output, $question);
117117

118-
$inputStream = $this->inputStream ?: STDIN;
118+
$inputStream = $this->inputStream ?: fopen('php://stdin', 'r');
119119
$autocomplete = $question->getAutocompleterCallback();
120120

121121
if (null === $autocomplete || !Terminal::hasSttyAvailable()) {

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8585
$this->displayCorrectFiles = $output->isVerbose();
8686

8787
if (['-'] === $filenames) {
88-
return $this->display($io, [$this->validate($this->getStdin())]);
88+
return $this->display($io, [$this->validate(file_get_contents('php://stdin'))]);
8989
}
9090

9191
// @deprecated to be removed in 5.0
@@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696

9797
@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);
9898

99-
return $this->display($io, [$this->validate($this->getStdin())]);
99+
return $this->display($io, [$this->validate(file_get_contents('php://stdin'))]);
100100
}
101101

102102
$filesInfo = [];
@@ -230,16 +230,6 @@ private function getFiles(string $fileOrDirectory)
230230
}
231231
}
232232

233-
private function getStdin(): string
234-
{
235-
$xliff = '';
236-
while (!feof(STDIN)) {
237-
$xliff .= fread(STDIN, 1024);
238-
}
239-
240-
return $xliff;
241-
}
242-
243233
private function getDirectoryIterator(string $directory)
244234
{
245235
$default = function ($directory) {

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
8888
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
8989

9090
if (['-'] === $filenames) {
91-
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
91+
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
9292
}
9393

9494
// @deprecated to be removed in 5.0
9595
if (!$filenames) {
9696
if (0 === ftell(STDIN)) {
9797
@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);
9898

99-
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
99+
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
100100
}
101101

102102
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
@@ -215,16 +215,6 @@ private function getFiles(string $fileOrDirectory): iterable
215215
}
216216
}
217217

218-
private function getStdin(): string
219-
{
220-
$yaml = '';
221-
while (!feof(STDIN)) {
222-
$yaml .= fread(STDIN, 1024);
223-
}
224-
225-
return $yaml;
226-
}
227-
228218
private function getParser(): Parser
229219
{
230220
if (!$this->parser) {

0 commit comments

Comments
 (0)
0