Skip to content

Commit d39b2f5

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: Add some typehint
2 parents 50ac6a7 + b468323 commit d39b2f5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

controller/service.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ apply the ``controller.service_arguments`` tag to your controller services::
3131
// src/Controller/HelloController.php
3232
namespace App\Controller;
3333

34+
use Symfony\Component\HttpFoundation\Response;
3435
use Symfony\Component\HttpKernel\Attribute\AsController;
3536
use Symfony\Component\Routing\Annotation\Route;
3637

3738
#[AsController]
3839
class HelloController
3940
{
4041
#[Route('/hello', name: 'hello', methods: ['GET'])]
41-
public function index()
42+
public function index(): Response
4243
{
4344
// ...
4445
}
@@ -60,12 +61,13 @@ a service like: ``App\Controller\HelloController::index``:
6061
// src/Controller/HelloController.php
6162
namespace App\Controller;
6263
64+
use Symfony\Component\HttpFoundation\Response;
6365
use Symfony\Component\Routing\Annotation\Route;
6466
6567
class HelloController
6668
{
6769
#[Route('/hello', name: 'hello', methods: ['GET'])]
68-
public function index()
70+
public function index(): Response
6971
{
7072
// ...
7173
}
@@ -127,7 +129,7 @@ which is a common practice when following the `ADR pattern`_
127129
#[Route('/hello/{name}', name: 'hello')]
128130
class Hello
129131
{
130-
public function __invoke($name = 'World')
132+
public function __invoke(string $name = 'World'): Response
131133
{
132134
return new Response(sprintf('Hello %s!', $name));
133135
}
@@ -192,7 +194,7 @@ service and use it directly::
192194
) {
193195
}
194196

195-
public function index($name)
197+
public function index(string $name): Response
196198
{
197199
$content = $this->twig->render(
198200
'hello/index.html.twig',

0 commit comments

Comments
 (0)