Skip to content

Commit 8759ffc

Browse files
committed
deprecated not passing dash symbol (-) to STDIN commands
1 parent 9d472c7 commit 8759ffc

File tree

8 files changed

+100
-30
lines changed

8 files changed

+100
-30
lines changed

UPGRADE-4.4.md

Lines 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

Lines 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

Lines 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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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($io), uniqid('sf_', true))]);
8989
}
9090

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

110+
private function getStdin(SymfonyStyle $io): string
111+
{
112+
$template = '';
113+
if (0 === ftell(STDIN)) {
114+
while (!feof(STDIN)) {
115+
$template .= fread(STDIN, 1024);
116+
}
117+
} else {
118+
$io->block('Write the template content (press <return> twice to stop)', null, 'fg=black;bg=yellow', ' ', true);
119+
$break = 0;
120+
while (true) {
121+
if ("\n" === $char = fgetc(STDIN)) {
122+
if (2 === ++$break) {
123+
break;
124+
}
125+
} else {
126+
$break = 0;
127+
}
128+
$template .= $char;
129+
}
130+
}
131+
132+
return $template;
133+
}
134+
110135
private function getFilesInfo(array $filenames)
111136
{
112137
$filesInfo = [];

src/Symfony/Component/Translation/CHANGELOG.md

Lines 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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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($io))]);
9398
}
9499

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

226-
private function getStdin(): ?string
231+
private function getStdin(SymfonyStyle $io): string
227232
{
228-
if (0 !== ftell(STDIN)) {
229-
return null;
230-
}
231-
232-
$inputs = '';
233-
while (!feof(STDIN)) {
234-
$inputs .= fread(STDIN, 1024);
233+
$xliff = '';
234+
if (0 === ftell(STDIN)) {
235+
while (!feof(STDIN)) {
236+
$xliff .= fread(STDIN, 1024);
237+
}
238+
} else {
239+
$io->block('Write the Xliff content (press <return> twice to stop)', null, 'fg=black;bg=yellow', ' ', true);
240+
$break = 0;
241+
while (true) {
242+
if ("\n" === $char = fgetc(STDIN)) {
243+
if (2 === ++$break) {
244+
break;
245+
}
246+
} else {
247+
$break = 0;
248+
}
249+
$xliff .= $char;
250+
}
235251
}
236252

237-
return $inputs;
253+
return $xliff;
238254
}
239255

240256
private function getDirectoryIterator(string $directory)

src/Symfony/Component/Yaml/CHANGELOG.md

Lines 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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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($io), $flags)]);
96101
}
97102

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

202-
private function getStdin(): ?string
207+
private function getStdin(SymfonyStyle $io): string
203208
{
204-
if (0 !== ftell(STDIN)) {
205-
return null;
206-
}
207-
208-
$inputs = '';
209-
while (!feof(STDIN)) {
210-
$inputs .= fread(STDIN, 1024);
209+
$yaml = '';
210+
if (0 === ftell(STDIN)) {
211+
while (!feof(STDIN)) {
212+
$yaml .= fread(STDIN, 1024);
213+
}
214+
} else {
215+
$io->block('Write the Yaml content (press <return> twice to stop)', null, 'fg=black;bg=yellow', ' ', true);
216+
$break = 0;
217+
while (true) {
218+
if ("\n" === $char = fgetc(STDIN)) {
219+
if (2 === ++$break) {
220+
break;
221+
}
222+
} else {
223+
$break = 0;
224+
}
225+
$yaml .= $char;
226+
}
211227
}
212228

213-
return $inputs;
229+
return $yaml;
214230
}
215231

216232
private function getParser()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy