Skip to content

Commit 0fc886d

Browse files
94noniwouterj
authored andcommitted
[Messenger] Document the validation middleware
1 parent dbd274c commit 0fc886d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

messenger.rst

+61
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,67 @@ may want to use:
17301730
],
17311731
]);
17321732
1733+
Other Middlewares
1734+
~~~~~~~~~~~~~~~~~
1735+
1736+
.. versionadded:: 4.1
1737+
1738+
The ``validation`` middleware was introduced in Symfony 4.1.
1739+
1740+
Add the ``validation`` middleware if you need to validate the message
1741+
object using the :doc:`Validator component <validator>` before handling it.
1742+
If validation fails, a ``ValidationFailedException`` will be thrown. The
1743+
:class:`Symfony\\Component\\Messenger\\Stamp\\ValidationStamp` can be used
1744+
to configure the validation groups.
1745+
1746+
.. configuration-block::
1747+
1748+
.. code-block:: yaml
1749+
1750+
# config/packages/messenger.yaml
1751+
framework:
1752+
messenger:
1753+
buses:
1754+
command_bus:
1755+
middleware:
1756+
- validation
1757+
1758+
.. code-block:: xml
1759+
1760+
<!-- config/packages/messenger.xml -->
1761+
<?xml version="1.0" encoding="UTF-8" ?>
1762+
<container xmlns="http://symfony.com/schema/dic/services"
1763+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1764+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1765+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1766+
https://symfony.com/schema/dic/services/services-1.0.xsd
1767+
http://symfony.com/schema/dic/symfony
1768+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1769+
1770+
<framework:config>
1771+
<framework:messenger>
1772+
<framework:bus name="command_bus">
1773+
<framework:middleware id="validation"/>
1774+
</framework:bus>
1775+
</framework:messenger>
1776+
</framework:config>
1777+
</container>
1778+
1779+
.. code-block:: php
1780+
1781+
// config/packages/messenger.php
1782+
$container->loadFromExtension('framework', [
1783+
'messenger' => [
1784+
'buses' => [
1785+
'command_bus' => [
1786+
'middleware' => [
1787+
'validation',
1788+
],
1789+
],
1790+
],
1791+
],
1792+
]);
1793+
17331794
Messenger Events
17341795
~~~~~~~~~~~~~~~~
17351796

0 commit comments

Comments
 (0)