@@ -31,14 +31,15 @@ apply the ``controller.service_arguments`` tag to your controller services::
31
31
// src/Controller/HelloController.php
32
32
namespace App\Controller;
33
33
34
+ use Symfony\Component\HttpFoundation\Response;
34
35
use Symfony\Component\HttpKernel\Attribute\AsController;
35
36
use Symfony\Component\Routing\Annotation\Route;
36
37
37
38
#[AsController]
38
39
class HelloController
39
40
{
40
41
#[Route('/hello', name: 'hello', methods: ['GET'])]
41
- public function index()
42
+ public function index(): Response
42
43
{
43
44
// ...
44
45
}
@@ -71,7 +72,7 @@ a service like: ``App\Controller\HelloController::index``:
71
72
/**
72
73
* @Route("/hello", name="hello", methods={"GET"})
73
74
*/
74
- public function index()
75
+ public function index(): Response
75
76
{
76
77
// ...
77
78
}
@@ -82,12 +83,13 @@ a service like: ``App\Controller\HelloController::index``:
82
83
// src/Controller/HelloController.php
83
84
namespace App\Controller;
84
85
86
+ use Symfony\Component\HttpFoundation\Response;
85
87
use Symfony\Component\Routing\Annotation\Route;
86
88
87
89
class HelloController
88
90
{
89
91
#[Route('/hello', name: 'hello', methods: ['GET'])]
90
- public function index()
92
+ public function index(): Response
91
93
{
92
94
// ...
93
95
}
@@ -151,7 +153,7 @@ which is a common practice when following the `ADR pattern`_
151
153
*/
152
154
class Hello
153
155
{
154
- public function __invoke($name = 'World')
156
+ public function __invoke(string $name = 'World'): Response
155
157
{
156
158
return new Response(sprintf('Hello %s!', $name));
157
159
}
@@ -168,7 +170,7 @@ which is a common practice when following the `ADR pattern`_
168
170
#[Route('/hello/{name}', name: 'hello')]
169
171
class Hello
170
172
{
171
- public function __invoke($name = 'World')
173
+ public function __invoke(string $name = 'World'): Response
172
174
{
173
175
return new Response(sprintf('Hello %s!', $name));
174
176
}
@@ -228,14 +230,14 @@ service and use it directly::
228
230
229
231
class HelloController
230
232
{
231
- private $twig;
233
+ private Environment $twig;
232
234
233
235
public function __construct(Environment $twig)
234
236
{
235
237
$this->twig = $twig;
236
238
}
237
239
238
- public function index($name)
240
+ public function index(string $name): Response
239
241
{
240
242
$content = $this->twig->render(
241
243
'hello/index.html.twig',
0 commit comments