34
34
*/
35
35
class QuestionHelper extends Helper
36
36
{
37
- /**
38
- * @var resource|null
39
- */
40
- private $ inputStream ;
41
-
42
37
private static bool $ stty = true ;
43
38
private static bool $ stdinIsInteractive ;
44
39
@@ -59,16 +54,15 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
59
54
return $ this ->getDefaultAnswer ($ question );
60
55
}
61
56
62
- if ($ input instanceof StreamableInputInterface && $ stream = $ input ->getStream ()) {
63
- $ this ->inputStream = $ stream ;
64
- }
57
+ $ inputStream = $ input instanceof StreamableInputInterface ? $ input ->getStream () : null ;
58
+ $ inputStream ??= STDIN ;
65
59
66
60
try {
67
61
if (!$ question ->getValidator ()) {
68
- return $ this ->doAsk ($ output , $ question );
62
+ return $ this ->doAsk ($ inputStream , $ output , $ question );
69
63
}
70
64
71
- $ interviewer = fn () => $ this ->doAsk ($ output , $ question );
65
+ $ interviewer = fn () => $ this ->doAsk ($ inputStream , $ output , $ question );
72
66
73
67
return $ this ->validateAttempts ($ interviewer , $ output , $ question );
74
68
} catch (MissingInputException $ exception ) {
@@ -98,13 +92,14 @@ public static function disableStty(): void
98
92
/**
99
93
* Asks the question to the user.
100
94
*
95
+ * @param resource $inputStream
96
+ *
101
97
* @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden
102
98
*/
103
- private function doAsk (OutputInterface $ output , Question $ question ): mixed
99
+ private function doAsk ($ inputStream , OutputInterface $ output , Question $ question ): mixed
104
100
{
105
101
$ this ->writePrompt ($ output , $ question );
106
102
107
- $ inputStream = $ this ->inputStream ?: \STDIN ;
108
103
$ autocomplete = $ question ->getAutocompleterCallback ();
109
104
110
105
if (null === $ autocomplete || !self ::$ stty || !Terminal::hasSttyAvailable ()) {
0 commit comments