8000 [Console] allow the answer to not be trimmed · symfony/symfony-docs@dcb0eaa · GitHub
[go: up one dir, main page]

Skip to content

Commit dcb0eaa

Browse files
SimperfitOskarStark
authored andcommitted
[Console] allow the answer to not be trimmed
1 parent 21198dc commit dcb0eaa

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
@@ -216,6 +216,30 @@ provide a callback function to dynamically generate suggestions::
216216

217217
The ``setAutocompleterCallback()`` method was introduced in Symfony 4.3.
218218

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

0 commit comments

Comments
 (0)
0