Skip to content

Commit 93da9d5

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Adding info about login throttling add missing return statement [symfony#17180] add missing link target Typo fix Adding note box about valid values for "interval" Deleting duplicate "default" [Console] Add return hint [Console] Add return for execute() [Console] add SignalableCommandInterface link Adding type hint Adding missing `use` [Routing] add missing action return hints Trying to fix code sample syntax
2 parents 74e436b + 1a7913d commit 93da9d5

File tree

8 files changed

+94
-27
lines changed

8 files changed

+94
-27
lines changed

best_practices.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ application behavior.
8888
:ref:`Use env vars in your project <config-env-vars>` to define these options
8989
and create multiple ``.env`` files to :ref:`configure env vars per environment <config-dot-env>`.
9090

91-
Use Secret for Sensitive Information
92-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
.. _use-secret-for-sensitive-information:
92+
93+
Use Secrets for Sensitive Information
94+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9395

9496
When your application has sensitive configuration - like an API key - you should
9597
store those securely via :doc:`Symfony’s secrets management system </configuration/secrets>`.

components/console/events.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Listeners receive a
190190

191191
If you use the Console component inside a Symfony application, commands can
192192
handle signals themselves. To do so, implement the
193-
``SignalableCommandInterface`` and subscribe to one or more signals::
193+
:class:`Symfony\\Component\\Console\\Command\\SignalableCommandInterface` and subscribe to one or more signals::
194194

195195
// src/Command/SomeCommand.php
196196
namespace App\Command;
@@ -208,7 +208,7 @@ handle signals themselves. To do so, implement the
208208
return [\SIGINT, \SIGTERM];
209209
}
210210

211-
public function handleSignal(int $signal)
211+
public function handleSignal(int $signal): void
212212
{
213213
if (\SIGINT === $signal) {
214214
// ...

components/console/helpers/questionhelper.rst

+59-13
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ the following to your command::
3434
{
3535
// ...
3636

37-
public function execute(InputInterface $input, OutputInterface $output)
37+
public function execute(InputInterface $input, OutputInterface $output): int
3838
{
3939
$helper = $this->getHelper('question');
4040
$question = new ConfirmationQuestion('Continue with this action?', false);
4141

4242
if (!$helper->ask($input, $output, $question)) {
4343
return Command::SUCCESS;
4444
}
45+
46+
// ... do something here
47+
48+
return Command::SUCCESS;
4549
}
4650
}
4751

@@ -75,12 +79,16 @@ if you want to know a bundle name, you can add this to your command::
7579
use Symfony\Component\Console\Question\Question;
7680

7781
// ...
78-
public function execute(InputInterface $input, OutputInterface $output)
82+
public function execute(InputInterface $input, OutputInterface $output): int
7983
{
8084
// ...
8185
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
8286

8387
$bundleName = $helper->ask($input, $output, $question);
88+
89+
// ... do something with the bundleName
90+
91+
return Commande::SUCCESS;
8492
}
8593

8694
The user will be asked "Please enter the name of the bundle". They can type
@@ -99,7 +107,7 @@ from a predefined list::
99107
use Symfony\Component\Console\Question\ChoiceQuestion;
100108

101109
// ...
102-
public function execute(InputInterface $input, OutputInterface $output)
110+
public function execute(InputInterface $input, OutputInterface $output): int
103111
{
104112
// ...
105113
$helper = $this->getHelper('question');
@@ -115,6 +123,8 @@ from a predefined list::
115123
$output->writeln('You have just selected: '.$color);
116124

117125
// ... do something with the color
126+
127+
return Commande::SUCCESS;
118128
}
119129

120130
The option which should be selected by default is provided with the third
@@ -138,7 +148,7 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
138148
use Symfony\Component\Console\Question\ChoiceQuestion;
139149

140150
// ...
141-
public function execute(InputInterface $input, OutputInterface $output)
151+
public function execute(InputInterface $input, OutputInterface $output): int
142152
{
143153
// ...
144154
$helper = $this->getHelper('question');
@@ -151,6 +161,8 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult
151161

152162
$colors = $helper->ask($input, $output, $question);
153163
$output->writeln('You have just selected: ' . implode(', ', $colors));
164+
165+
return Commande::SUCCESS;
154166
}
155167

156168
Now, when the user enters ``1,2``, the result will be:
@@ -168,7 +180,7 @@ will be autocompleted as the user types::
168180
use Symfony\Component\Console\Question\Question;
169181

170182
// ...
171-
public function execute(InputInterface $input, OutputInterface $output)
183+
public function execute(InputInterface $input, OutputInterface $output): int
172184
{
173185
// ...
174186
$helper = $this->getHelper('question');
@@ -178,6 +190,10 @@ will be autocompleted as the user types::
178190
$question->setAutocompleterValues($bundles);
179191

180192
$bundleName = $helper->ask($input, $output, $question);
193+
194+
// ... do something with the bundleName
195+
196+
return Commande::SUCCESS;
181197
}
182198

183199
In more complex use cases, it may be necessary to generate suggestions on the
@@ -187,7 +203,7 @@ provide a callback function to dynamically generate suggestions::
187203
use Symfony\Component\Console\Question\Question;
188204

189205
// ...
190-
public function execute(InputInterface $input, OutputInterface $output)
206+
public function execute(InputInterface $input, OutputInterface $output): int
191207
{
192208
$helper = $this->getHelper('question');
193209

@@ -213,6 +229,10 @@ provide a callback function to dynamically generate suggestions::
213229
$question->setAutocompleterCallback($callback);
214230

215231
$filePath = $helper->ask($input, $output, $question);
232+
233+
// ... do something with the filePath
234+
235+
return Commande::SUCCESS;
216236
}
217237

218238
Do not Trim the Answer
@@ -224,7 +244,7 @@ You can also specify if you want to not trim the answer by setting it directly w
224244
use Symfony\Component\Console\Question\Question;
225245

226246
// ...
227-
public function execute(InputInterface $input, OutputInterface $output)
247+
public function execute(InputInterface $input, OutputInterface $output): int
228248
{
229249
// ...
230250
$helper = $this->getHelper('question');
@@ -233,6 +253,10 @@ You can also specify if you want to not trim the answer by setting it directly w
233253
$question->setTrimmable(false);
234254
// if the users inputs 'elsa ' it will not be trimmed and you will get 'elsa ' as value
235255
$name = $helper->ask($input, $output, $question);
256+
257+
// ... do something with the name
258+
259+
return Commande::SUCCESS;
236260
}
237261

238262
Accept Multiline Answers
@@ -246,7 +270,7 @@ the response to a question should allow multiline answers by passing ``true`` to
246270
use Symfony\Component\Console\Question\Question;
247271

248272
// ...
249-
public function execute(InputInterface $input, OutputInterface $output)
273+
public function execute(InputInterface $input, OutputInterface $output): int
250274
{
251275
// ...
252276
$helper = $this->getHelper('question');
@@ -255,6 +279,10 @@ the response to a question should allow multiline answers by passing ``true`` to
255279
$question->setMultiline(true);
256280

257281
$answer = $helper->ask($input, $output, $question);
282+
283+
// ... do something with the answer
284+
285+
return Commande::SUCCESS;
258286
}
259287

260288
Multiline questions stop reading user input after receiving an end-of-transmission
@@ -269,7 +297,7 @@ convenient for passwords::
269297
use Symfony\Component\Console\Question\Question;
270298

271299
// ...
272-
public function execute(InputInterface $input, OutputInterface $output)
300+
public function execute(InputInterface $input, OutputInterface $output): int
273301
{
274302
// ...
275303
$helper = $this->getHelper('question');
@@ -279,6 +307,10 @@ convenient for passwords::
279307
$question->setHiddenFallback(false);
280308

281309
$password = $helper->ask($input, $output, $question);
310+
311+
// ... do something with the password
312+
313+
return Commande::SUCCESS;
282314
}
283315

284316
.. caution::
@@ -302,13 +334,15 @@ convenient for passwords::
302334
use Symfony\Component\Console\Question\ChoiceQuestion;
303335

304336
// ...
305-
public function execute(InputInterface $input, OutputInterface $output)
337+
public function execute(InputInterface $input, OutputInterface $output): int
306338
{
307339
// ...
308340
$helper = $this->getHelper('question');
309341
QuestionHelper::disableStty();
310342

311343
// ...
344+
345+
return Commande::SUCCESS;
312346
}
313347

314348
Normalizing the Answer
@@ -324,7 +358,7 @@ method::
324358
use Symfony\Component\Console\Question\Question;
325359

326360
// ...
327-
public function execute(InputInterface $input, OutputInterface $output)
361+
public function execute(InputInterface $input, OutputInterface $output): int
328362
{
329363
// ...
330364
$helper = $this->getHelper('question');
@@ -336,6 +370,10 @@ method::
336370
});
337371

338372
$bundleName = $helper->ask($input, $output, $question);
373+
374+
// ... do something with the bundleName
375+
376+
return Commande::SUCCESS;
339377
}
340378

341379
.. caution::
@@ -358,7 +396,7 @@ method::
358396
use Symfony\Component\Console\Question\Question;
359397

360398
// ...
361-
public function execute(InputInterface $input, OutputInterface $output)
399+
public function execute(InputInterface $input, OutputInterface $output): int
362400
{
363401
// ...
364402
$helper = $this->getHelper('question');
@@ -376,6 +414,10 @@ method::
376414
$question->setMaxAttempts(2);
377415

378416
$bundleName = $helper->ask($input, $output, $question);
417+
418+
// ... do something with the bundleName
419+
420+
return Commande::SUCCESS;
379421
}
380422

381423
The ``$validator`` is a callback which handles the validation. It should
@@ -414,7 +456,7 @@ You can also use a validator with a hidden question::
414456
use Symfony\Component\Console\Question\Question;
415457

416458
// ...
417-
public function execute(InputInterface $input, OutputInterface $output)
459+
public function execute(InputInterface $input, OutputInterface $output): int
418460
{
419461
// ...
420462
$helper = $this->getHelper('question');
@@ -434,6 +476,10 @@ You can also use a validator with a hidden question::
434476
$question->setMaxAttempts(20);
435477

436478
$password = $helper->ask($input, $output, $question);
479+
480+
// ... do something with the password
481+
482+
return Commande::SUCCESS;
437483
}
438484

439485
Testing a Command that Expects Input

components/console/helpers/table.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ set the headers, set the rows and then render the table::
2828

2929
class SomeCommand extends Command
3030
{
31-
public function execute(InputInterface $input, OutputInterface $output)
31+
public function execute(InputInterface $input, OutputInterface $output): int
3232
{
3333
$table = new Table($output);
3434
$table
@@ -41,6 +41,8 @@ set the headers, set the rows and then render the table::
4141
])
4242
;
4343
$table->render();
44+
45+
return Command::SUCCESS;
4446
}
4547
}
4648

@@ -427,7 +429,7 @@ The only requirement to append rows is that the table must be rendered inside a
427429

428430
class SomeCommand extends Command
429431
{
430-
public function execute(InputInterface $input, OutputInterface $output)
432+
public function execute(InputInterface $input, OutputInterface $output): int
431433
{
432434
$section = $output->section();
433435
$table = new Table($section);
@@ -436,6 +438,8 @@ The only requirement to append rows is that the table must be rendered inside a
436438
$table->render();
437439

438440
$table->appendRow(['Symfony']);
441+
442+
return Command::SUCCESS;
439443
}
440444
}
441445

rate_limiter.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defensive measure to protect services from excessive use (intended or not) and
77
maintain their availability. It's also useful to control your internal or
88
outbound processes (e.g. limit the number of simultaneously processed messages).
99

10-
Symfony uses these rate limiters in built-in features like "login throttling",
10+
Symfony uses these rate limiters in built-in features like :ref:`login throttling <security-login-throttling>`,
1111
which limits how many failed login attempts a user can make in a given period of
1212
time, but you can use them for your own features too.
1313

routing.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ do so, create a :doc:`controller class </controller>` like the following:
6363
class BlogController extends AbstractController
6464
{
6565
#[Route('/blog', name: 'blog_list')]
66-
public function list()
66+
public function list(): Response
6767
{
6868
// ...
6969
}
@@ -895,7 +895,7 @@ optional ``priority`` parameter in those routes to control their priority:
895895
* This route has a greedy pattern and is defined first.
896896
*/
897897
#[Route('/blog/{slug}', name: 'blog_show')]
898-
public function show(string $slug)
898+
public function show(string $slug): Response
899899
{
900900
// ...
901901
}
@@ -904,7 +904,7 @@ optional ``priority`` parameter in those routes to control their priority:
904904
* This route could not be matched without defining a higher priority than 0.
905905
*/
906906
#[Route('/blog/list', name: 'blog_list', priority: 2)]
907-
public function list()
907+
public function list(): Response
908908
{
909909
// ...
910910
}
@@ -2107,7 +2107,7 @@ session shouldn't be used when matching a request:
21072107
class MainController extends AbstractController
21082108
{
21092109
#[Route('/', name: 'homepage', stateless: true)]
2110-
public function homepage()
2110+
public function homepage(): Response
21112111
{
21122112
// ...
21132113
}

0 commit comments

Comments
 (0)