Skip to content

Commit 2d9ba82

Browse files
committed
Merge branch '4.2'
* 4.2: Show Docker as the preferred way to build docs locally Add an example to the invokable controllers section
2 parents af786dd + 8785e39 commit 2d9ba82

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

contributing/documentation/overview.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,22 @@ GitHub, click on the **Show all checks** link and finally, click on the
249249
Build the Documentation Locally
250250
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251251

252-
Alternatively you can build the documentation on your own computer for testing
253-
purposes following these steps:
252+
If you have Docker installed on your machine, run these commands to build the
253+
docs:
254+
255+
.. code-block:: terminal
256+
257+
# build the image...
258+
$ docker build . -t symfony-docs
259+
260+
# ...and start the local web server
261+
# (if it's already in use, change the '8080' port by any other port)
262+
$ docker run --rm -p 8080:80 symfony-docs
263+
264+
You can now read the docs at ``http://127.0.0.1:8080`` (if you use a virtual
265+
machine, browse its IP instead of localhost; e.g. ``http://192.168.99.100:8080``).
266+
267+
If you don't use Docker, follow these steps to build the docs locally:
254268

255269
#. Install `pip`_ as explained in the `pip installation`_ article;
256270

controller/service.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,24 @@ a service like: ``App\Controller\HelloController::index``:
8080
Invokable 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

87102
Alternatives 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

Comments
 (0)