@@ -84,9 +84,7 @@ class Demo
8484}
8585```
8686
87- ## Create the console command
88-
89- ### Strategy 1 (recommended): Use the ` form ` helper
87+ ## Create the console command; use the ` form ` helper
9088
9189``` php
9290<?php
@@ -116,55 +114,8 @@ class TestCommand extends Command
116114}
117115```
118116
119- ### Strategy 2: implement ` FormBasedCommand `
120-
121- You could also implement ` FormBasedCommand ` :
122-
123- ``` php
124- <?php
125-
126- use Symfony\Component\Console\Command\Command;
127- use Symfony\Component\Console\Input\InputInterface;
128- use Symfony\Component\Console\Output\OutputInterface;
129- use Matthias\SymfonyConsoleForm\Console\Command\FormBasedCommand;
130- use Matthias\SymfonyConsoleForm\Console\Command\FormBasedCommandCapabilities;
131-
132- class TestCommand extends Command implements FormBasedCommand
133- {
134- // use this trait to prevent code duplication
135- use FormBasedCommandCapabilities;
136-
137- protected function configure()
138- {
139- $this->setName('form:demo');
140-
141- // you don't need to configure any options here, this is all taken care of
142- }
143-
144- protected function formType()
145- {
146- // return the form type (can be a string) which should be used for interaction with the user
147-
148- return new DemoType();
149- }
150-
151- protected function execute(InputInterface $input, OutputInterface $output)
152- {
153- $formData = $this->formData();
154-
155- // $formData is the valid and populated form data object/array
156- ...
157- }
158- }
159- ```
160-
161- Then run ` app/console form:demo ` and you'll see the following interaction:
162-
163117![ ] ( doc/interaction.png )
164118
165- The first strategy is preferred since it allows you to interact with different forms instead of just one form (as is
166- the case when you pick the second strategy).
167-
168119When you provide command-line options with the names of the form fields, those values will be used as default values.
169120
170121If you add the ` --no-interaction ` option when running the command, it will submit the form using the input options you provided.
0 commit comments