Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4234601

Browse filesBrowse files
committed
feature #33496 Deprecated not passing dash symbol (-) to STDIN commands (yceruto)
This PR was merged into the 4.4 branch. Discussion ---------- Deprecated not passing dash symbol (-) to STDIN commands | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #33446 (comment) | License | MIT | Doc PR | - Follow-up #33446 > There's a conflict here: when no argument was provided, the command also reads from STDIN. So now, it reads from STDIN, and if there is nothing there, reads from the default template. This has been caught in php/php-src#4672 > This creates an ambiguous situation - maybe one did pipe nothing but doesn't expect the default template dir to be linted. > I'd suggest resolving the ambiguity by reading from STDIN only when explicitly asked for. Passing - as argument could the way. And we could trigger a deprecation for now. For consistency, the other 2 lint commands (`lint:yaml` and `lint:xliff`) have been touched as well. The plan for 5.0 is read from the STDIN only when `-` is given. /cc @nicolas-grekas Commits ------- 586f299 deprecated not passing dash symbol (-) to STDIN commands
2 parents 8f84347 + 586f299 commit 4234601
Copy full SHA for 4234601

File tree

8 files changed

+56
-31
lines changed
Filter options

8 files changed

+56
-31
lines changed

‎UPGRADE-4.4.md

Copy file name to clipboardExpand all lines: UPGRADE-4.4.md
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ Translation
207207
-----------
208208

209209
* Deprecated support for using `null` as the locale in `Translator`.
210+
* Deprecated accepting STDIN implicitly when using the `lint:xliff` command, use `lint:xliff -` (append a dash) instead to make it explicit.
210211

211212
TwigBridge
212213
----------
213214

214215
* Deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the
215216
`DebugCommand::__construct()` method, swap the variables position.
217+
* Deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
216218

217219
TwigBundle
218220
----------
@@ -326,3 +328,8 @@ WebServerBundle
326328
---------------
327329

328330
* The bundle is deprecated and will be removed in 5.0.
331+
332+
Yaml
333+
----
334+
335+
* Deprecated accepting STDIN implicitly when using the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Translation
531531
* The `MessageSelector`, `Interval` and `PluralizationRules` classes have been removed, use `IdentityTranslator` instead
532532
* The `Translator::getFallbackLocales()` and `TranslationDataCollector::getFallbackLocales()` method are now internal
533533
* The `Translator::transChoice()` method has been removed in favor of using `Translator::trans()` with "%count%" as the parameter driving plurals
534+
* Removed support for implicit STDIN usage in the `lint:xliff` command, use `lint:xliff -` (append a dash) instead to make it explicit.
534535

535536
TwigBundle
536537
----------
@@ -548,6 +549,7 @@ TwigBridge
548549
* removed the `$requestStack` and `$requestContext` arguments of the
549550
`HttpFoundationExtension`, pass a `Symfony\Component\HttpFoundation\UrlHelper`
550551
instance as the only argument instead
552+
* Removed support for implicit STDIN usage in the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
551553

552554
Validator
553555
--------
@@ -653,6 +655,7 @@ Yaml
653655

654656
* The parser is now stricter and will throw a `ParseException` when a
655657
mapping is found inside a multi-line string.
658+
* Removed support for implicit STDIN usage in the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.
656659

657660
WebProfilerBundle
658661
-----------------

‎src/Symfony/Bridge/Twig/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the
99
`DebugCommand::__construct()` method, swap the variables position.
1010
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided
11+
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
1112

1213
4.3.0
1314
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/LintCommand.php
+17-7Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function configure()
5050
$this
5151
->setDescription('Lints a template and outputs encountered errors')
5252
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
53-
->addArgument('filename', InputArgument::IS_ARRAY)
53+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5454
->setHelp(<<<'EOF'
5555
The <info>%command.name%</info> command lints a template and outputs to STDOUT
5656
the first encountered syntax error.
@@ -77,15 +77,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
7777
{
7878
$io = new SymfonyStyle($input, $output);
7979
$filenames = $input->getArgument('filename');
80+
$hasStdin = '-' === ($filenames[0] ?? '');
8081

81-
if (0 === \count($filenames)) {
82-
if (0 === ftell(STDIN)) {
83-
$template = '';
84-
while (!feof(STDIN)) {
85-
$template .= fread(STDIN, 1024);
82+
if ($hasStdin || 0 === \count($filenames)) {
83+
if ($hasStdin || 0 === ftell(STDIN)) { // remove 0 === ftell(STDIN) check in 5.0
84+
if (!$hasStdin) {
85+
@trigger_error('Calling to the "lint:twig" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
8686
}
8787

88-
return $this->display($input, $output, $io, [$this->validate($template, uniqid('sf_', true))]);
88+
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
8989
}
9090

9191
$loader = $this->twig->getLoader();
@@ -107,6 +107,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
107107
return $this->display($input, $output, $io, $filesInfo);
108108
}
109109

110+
private function getStdin(): string
111+
{
112+
$template = '';
113+
while (!feof(STDIN)) {
114+
$template .= fread(STDIN, 1024);
115+
}
116+
117+
return $template;
118+
}
119+
110120
private function getFilesInfo(array $filenames)
111121
{
112122
$filesInfo = [];

‎src/Symfony/Component/Translation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated support for using `null` as the locale in `Translator`
8+
* deprecated accepting STDIN implicitly when using the `lint:xliff` command, use `lint:xliff -` (append a dash) instead to make it explicit.
89

910
4.3.0
1011
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Command/XliffLintCommand.php
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function configure()
5353
{
5454
$this
5555
->setDescription('Lints a XLIFF file and outputs encountered errors')
56-
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
56+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5757
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5858
->setHelp(<<<EOF
5959
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
@@ -83,13 +83,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383
$filenames = (array) $input->getArgument('filename');
8484
$this->format = $input->getOption('format');
8585
$this->displayCorrectFiles = $output->isVerbose();
86+
$hasStdin = '-' === ($filenames[0] ?? '');
8687

87-
if (0 === \count($filenames)) {
88-
if (!$stdin = $this->getStdin()) {
88+
if ($hasStdin || 0 === \count($filenames)) {
89+
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
8990
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9091
}
9192

92-
return $this->display($io, [$this->validate($stdin)]);
93+
if (!$hasStdin) {
94+
@trigger_error('Calling to the "lint:xliff" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
95+
}
96+
97+
return $this->display($io, [$this->validate($this->getStdin())]);
9398
}
9499

95100
$filesInfo = [];
@@ -223,18 +228,14 @@ private function getFiles(string $fileOrDirectory)
223228
}
224229
}
225230

226-
private function getStdin(): ?string
231+
private function getStdin(): string
227232
{
228-
if (0 !== ftell(STDIN)) {
229-
return null;
230-
}
231-
232-
$inputs = '';
233+
$xliff = '';
233234
while (!feof(STDIN)) {
234-
$inputs .= fread(STDIN, 1024);
235+
$xliff .= fread(STDIN, 1024);
235236
}
236237

237-
return $inputs;
238+
return $xliff;
238239
}
239240

240241
private function getDirectoryIterator(string $directory)

‎src/Symfony/Component/Yaml/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Added support to dump `null` as `~` by using the `Yaml::DUMP_NULL_AS_TILDE` flag.
8+
* deprecated accepting STDIN implicitly when using the `lint:yaml` command, use `lint:yaml -` (append a dash) instead to make it explicit.
89

910
4.3.0
1011
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Command/LintCommand.php
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function configure()
5454
{
5555
$this
5656
->setDescription('Lints a file and outputs encountered errors')
57-
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
57+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
5858
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5959
->addOption('parse-tags', null, InputOption::VALUE_NONE, 'Parse custom tags')
6060
->setHelp(<<<EOF
@@ -86,13 +86,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
$this->format = $input->getOption('format');
8787
$this->displayCorrectFiles = $output->isVerbose();
8888
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
89+
$hasStdin = '-' === ($filenames[0] ?? '');
8990

90-
if (0 === \count($filenames)) {
91-
if (!$stdin = $this->getStdin()) {
91+
if ($hasStdin || 0 === \count($filenames)) {
92+
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
9293
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9394
}
9495

95-
return $this->display($io, [$this->validate($stdin, $flags)]);
96+
if (!$hasStdin) {
97+
@trigger_error('Calling to the "lint:yaml" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
98+
}
99+
100+
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
96101
}
97102

98103
$filesInfo = [];
@@ -199,18 +204,14 @@ private function getFiles(string $fileOrDirectory)
199204
}
200205
}
201206

202-
private function getStdin(): ?string
207+
private function getStdin(): string
203208
{
204-
if (0 !== ftell(STDIN)) {
205-
return null;
206-
}
207-
208-
$inputs = '';
209+
$yaml = '';
209210
while (!feof(STDIN)) {
210-
$inputs .= fread(STDIN, 1024);
211+
$yaml .= fread(STDIN, 1024);
211212
}
212213

213-
return $inputs;
214+
return $yaml;
214215
}
215216

216217
private function getParser()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.