You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mercure.rst
+35-30Lines changed: 35 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -57,16 +57,17 @@ can be downloaded as a static binary from `Mercure.rocks`_.
57
57
A Docker image, a Helm chart for Kubernetes
58
58
and a managed, High Availability Hub are also provided.
59
59
60
-
If you use `Symfony Docker`_ or the `API Platform distribution`_,
61
-
a Mercure Hub is automatically installed and your Symfony application
62
-
is automatically configured to use it.
63
-
You can jump directly to the next section.
60
+
If you use `Symfony Docker`_ or the `API Platform distribution`_, a Mercure Hub
61
+
is automatically installed and your Symfony application is automatically
62
+
configured to use it. You can jump directly to the next section.
64
63
65
64
If you use the :doc:`Symfony Local Web Server </setup/symfony_server>`,
66
-
a Mercure hub will be automatically available as a Docker service thanks to its :ref:`Docker integration <symfony-server-docker>.
65
+
a Mercure hub will be automatically available as a Docker service thanks to its
66
+
:ref:`Docker integration <symfony-server-docker>.
67
67
68
-
Be sure that recent versions of Docker and Docker Compose are properly installed on your computer
69
-
and to start the Symfony Local Web Server with the ``--no-tls`` option:
68
+
Be sure that recent versions of Docker and Docker Compose are properly installed
69
+
on your computer and to start the Symfony Local Web Server with the ``--no-tls``
70
+
option:
70
71
71
72
.. code-block:: terminal
72
73
@@ -81,9 +82,9 @@ Run this command to install the Mercure support before using it:
81
82
82
83
$ composer require mercure
83
84
84
-
:ref:`Symfony Flex <symfony-flex>` has automatically installed and configured MercureBundle.
85
-
It also created (if needed) and configured a Docker Compose definition that provides a Mercure service.
86
-
Run ``docker-compose up`` to start it.
85
+
:ref:`Symfony Flex <symfony-flex>` has automatically installed and configured
86
+
MercureBundle. It also created (if needed) and configured a Docker Compose
87
+
definition that provides a Mercure service. Run ``docker-compose up`` to start it.
87
88
88
89
Configuration
89
90
-------------
@@ -94,8 +95,9 @@ The preferred way to configure the MercureBundle is using
94
95
When MercureBundle has been installed, the ``.env`` file of your project
95
96
has been updated by the Flex recipe to include the available env vars.
96
97
97
-
If you use the Symfony Local Web Server, Symfony Docker or the API Platform distribution,
98
-
the Symfony app is automatically configured and you can skip straight to the next section.
98
+
If you use the Symfony Local Web Server, Symfony Docker or the API Platform
99
+
distribution, the Symfony app is automatically configured and you can skip
100
+
straight to the next section.
99
101
100
102
Otherwise, set the URL of your hub as the value of the ``MERCURE_URL``
101
103
and ``MERCURE_PUBLIC_URL`` env vars.
@@ -251,10 +253,12 @@ Subscribing to updates in JavaScript from a Twig template is straightforward:
251
253
}
252
254
<script>
253
255
254
-
The ``mercure()`` Twig function will generate the URL of the Mercure hub according to the configuration.
255
-
The URL will include the ``topic`` query parameters corresponding to the topics passed as first argument.
256
+
The ``mercure()`` Twig function will generate the URL of the Mercure hub
257
+
according to the configuration. The URL will include the ``topic`` query
258
+
parameters corresponding to the topics passed as first argument.
256
259
257
-
If you want to access to this URL from an external JavaScript file, generate the URL in a dedicated HTML element:
260
+
If you want to access to this URL from an external JavaScript file, generate the
261
+
URL in a dedicated HTML element:
258
262
259
263
.. code:: twig
260
264
@@ -397,11 +401,11 @@ a JWT containing a topic selector matching by the update's topic.
397
401
To provide this JWT, the subscriber can use a cookie,
398
402
or a ``Authorization`` HTTP header.
399
403
400
-
Cookies can be set automatically by Symfony by passing the appropriate options to the ``mercure()`` Twig function.
401
-
Cookies set by Symfony will be automatically passed by the browsers to the Mercure hub
402
-
if the ``withCredentials`` attribute of the ``EventSource`` class is set to ``true``.
403
-
Then, the Hub will verify the validity of the provided JWT, and extract the topic selectors
404
-
from it.
404
+
Cookies can be set automatically by Symfony by passing the appropriate options
405
+
to the ``mercure()`` Twig function. Cookies set by Symfony will be automatically
406
+
passed by the browsers to the Mercure hub if the ``withCredentials`` attribute
407
+
of the ``EventSource`` class is set to ``true``. Then, the Hub will verify the
408
+
validity of the provided JWT, and extract the topic selectors from it.
405
409
406
410
.. code-block:: twig
407
411
@@ -413,8 +417,8 @@ from it.
413
417
414
418
The supported options are:
415
419
416
-
* ``subscribe``: the list of topic selectors to include in the ``mercure.subscribe`` claim of the JWT
417
-
* ``publish``: the list of topic selectors to include in the ``mercure.publish`` claim of the JWT
420
+
* ``subscribe``: the list of topic selectors to include in the ``mercure.subscribe`` claim of the JWT
421
+
* ``publish``: the list of topic selectors to include in the ``mercure.publish`` claim of the JWT
418
422
* ``additionalClaims``: extra claims to include in the JWT (expiration date, token ID...)
419
423
420
424
Using cookies is the most secure and preferred way when the client is a web
@@ -444,12 +448,12 @@ is the way to go.
444
448
Programmatically Setting The Cookie
445
449
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
446
450
447
-
Sometimes, it can be convenient to set the authorization cookie from
448
-
your code instead of using the Twig function.
449
-
MercureBundle provides a convenient service, :class:`Symfony\\Component\\Mercure\\Authorization`, to do so.
451
+
Sometimes, it can be convenient to set the authorization cookie from your code
452
+
instead of using the Twig function. MercureBundle provides a convenient service,
453
+
:class:`Symfony\\Component\\Mercure\\Authorization`, to do so.
450
454
451
-
In the following example controller,
452
-
the added cookie contains a JWT, itself containing the appropriate topic selector.
455
+
In the following example controller, the added cookie contains a JWT, itself
456
+
containing the appropriate topic selector.
453
457
454
458
And here is the controller::
455
459
@@ -714,9 +718,10 @@ it will be handled automatically::
714
718
Going further
715
719
-------------
716
720
717
-
* The Mercure protocol is also supported by :doc:`the Notifier component </notifier>`. Use it to send push notifications to web browsers.
718
-
* `Symfony UX Turbo`_ is a library using Mercure to provide the same experience as with Single Page Applications but without having to write a single line of JavaScript!
719
-
721
+
* The Mercure protocol is also supported by :doc:`the Notifier component </notifier>`.
722
+
Use it to send push notifications to web browsers.
723
+
* `Symfony UX Turbo`_ is a library using Mercure to provide the same experience
724
+
as with Single Page Applications but without having to write a single line of JavaScript!
0 commit comments