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