@@ -80,9 +80,24 @@ a service like: ``App\Controller\HelloController::index``:
8080Invokable Controllers
8181---------------------
8282
83- If your controller implements the ``__invoke() `` method - popular with the
84- Action-Domain-Response (ADR) pattern, you can refer to the service id
85- without the method (``App\Controller\HelloController `` for example).
83+ Controllers can also define a single action using the ``__invoke() `` method,
84+ which is a common practice when following the `ADR pattern `_
85+ (Action-Domain-Responder)::
86+
87+ // src/Controller/Hello.php
88+ use Symfony\Component\HttpFoundation\Response;
89+ use Symfony\Component\Routing\Annotation\Route;
90+
91+ /**
92+ * @Route("/hello/{name}", name="hello")
93+ */
94+ class Hello
95+ {
96+ public function __invoke($name = 'World')
97+ {
98+ return new Response(sprintf('Hello %s!', $name));
99+ }
100+ }
86101
87102Alternatives to base Controller Methods
88103---------------------------------------
@@ -141,3 +156,4 @@ If you want to know what type-hints to use for each service, see the
141156.. _`base Controller class` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
142157.. _`ControllerTrait` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
143158.. _`AbstractController` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php
159+ .. _`ADR pattern` : https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder
0 commit comments