Skip to content

Commit 9253a0c

Browse files
committed
feature #11603 [Console] allow the answer to not be trimmed (Simperfit)
This PR was squashed before being merged into the 4.4 branch (closes #11603). Discussion ---------- [Console] allow the answer to not be trimmed <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> This documents the new flag in the Question class to allow the answer to not be trimmed Commits ------- dcb0eaa [Console] allow the answer to not be trimmed
2 parents 15875d0 + dcb0eaa commit 9253a0c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/console/helpers/questionhelper.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,30 @@ provide a callback function to dynamically generate suggestions::
218218

219219
The ``setAutocompleterCallback()`` method was introduced in Symfony 4.3.
220220

221+
Do not Trim the Answer
222+
~~~~~~~~~~~~~~~~~~~~~~
223+
224+
You can also specify if you want to not trim the answer by setting it directly with
225+
:method:`Symfony\\Component\\Console\\Question\\Question::setTrimmable`::
226+
227+
use Symfony\Component\Console\Question\Question;
228+
229+
// ...
230+
public function execute(InputInterface $input, OutputInterface $output)
231+
{
232+
// ...
233+
$helper = $this->getHelper('question');
234+
235+
$question = new Question('What is the name of the child?');
236+
$question->setTrimmable(false);
237+
// if the users inputs 'elsa ' it will not be trimmed and you will get 'elsa ' as value
238+
$name = $helper->ask($input, $output, $question);
239+
}
240+
241+
.. versionadded:: 4.4
242+
243+
The ``setTrimmable()`` method was introduced in Symfony 4.4.
244+
221245
Hiding the User's Response
222246
~~~~~~~~~~~~~~~~~~~~~~~~~~
223247

0 commit comments

Comments
 (0)