Skip to content

Commit ce28de7

Browse files
committed
[Console] allow the answer to not be trimmed
1 parent 21198dc commit ce28de7

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)
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