use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\StreamableInputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
return $question->getDefault();
}
+ if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
+ $this->inputStream = $stream;
+ }
+
if (!$question->getValidator()) {
return $this->doAsk($output, $question);
}
- $that = $this;
-
- $interviewer = function () use ($output, $question, $that) {
- return $that->doAsk($output, $question);
+ $interviewer = function () use ($output, $question) {
+ return $this->doAsk($output, $question);
};
return $this->validateAttempts($interviewer, $output, $question);
*
* This is mainly useful for testing purpose.
*
+ * @deprecated since version 3.2, to be removed in 4.0. Use
+ * StreamableInputInterface::setStream() instead.
+ *
* @param resource $stream The input stream
*
* @throws InvalidArgumentException In case the stream is not a resource
*/
public function setInputStream($stream)
{
+ @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::setStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED);
+
if (!is_resource($stream)) {
throw new InvalidArgumentException('Input stream must be a valid resource.');
}
/**
* Returns the helper's input stream.
*
+ * @deprecated since version 3.2, to be removed in 4.0. Use
+ * StreamableInputInterface::getStream() instead.
+ *
* @return resource
*/
public function getInputStream()
{
+ if (0 === func_num_args() || func_get_arg(0)) {
+ @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::getStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED);
+ }
+
return $this->inputStream;
}
/**
* Asks the question to the user.
*
- * This method is public for PHP 5.3 compatibility, it should be private.
- *
* @param OutputInterface $output
* @param Question $question
*
* @return bool|mixed|null|string
*
- * @throws \Exception
- * @throws \RuntimeException
+ * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden
*/
- public function doAsk(OutputInterface $output, Question $question)
+ private function doAsk(OutputInterface $output, Question $question)
{
$this->writePrompt($output, $question);
if ($question->isHidden()) {
try {
$ret = trim($this->getHiddenResponse($output, $inputStream));
- } catch (\RuntimeException $e) {
+ } catch (RuntimeException $e) {
if (!$question->isHiddenFallback()) {
throw $e;
}
*
* @throws \Exception In case the max number of attempts has been reached and no valid response has been given
*/
- private function validateAttempts($interviewer, OutputInterface $output, Question $question)
+ private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question)
{
$error = null;
$attempts = $question->getMaxAttempts();