@@ -2152,6 +2152,12 @@ the consumer (e.g. render a template with links). This middleware stores the
2152
2152
original request context (i.e. the host, the HTTP port, etc.) which is needed
2153
2153
when building absolute URLs.
2154
2154
2155
+ Add the ``validation `` middleware if you need to validate the message
2156
+ object using the :doc: `Validator component <validator >` before handling it.
2157
+ If validation fails, a ``ValidationFailedException `` will be thrown. The
2158
+ :class: `Symfony\\ Component\\ Messenger\\ Stamp\\ ValidationStamp ` can be used
2159
+ to configure the validation groups.
2160
+
2155
2161
.. configuration-block ::
2156
2162
2157
2163
.. code-block :: yaml
@@ -2163,6 +2169,7 @@ when building absolute URLs.
2163
2169
command_bus :
2164
2170
middleware :
2165
2171
- router_context
2172
+ - validation
2166
2173
2167
2174
.. code-block :: xml
2168
2175
@@ -2180,6 +2187,7 @@ when building absolute URLs.
2180
2187
<framework : messenger >
2181
2188
<framework : bus name =" command_bus" >
2182
2189
<framework : middleware id =" router_context" />
2190
+ <framework : middleware id =" validation" />
2183
2191
</framework : bus >
2184
2192
</framework : messenger >
2185
2193
</framework : config >
@@ -2195,70 +2203,9 @@ when building absolute URLs.
2195
2203
2196
2204
$bus = $messenger->bus('command_bus');
2197
2205
$bus->middleware()->id('router_context');
2206
+ $bus->middleware()->id('validation');
2198
2207
};
2199
2208
2200
-
2201
- Other Middlewares
2202
- ~~~~~~~~~~~~~~~~~
2203
-
2204
- .. versionadded :: 4.1
2205
-
2206
- The ``validation `` middleware was introduced in Symfony 4.1.
2207
-
2208
- Add the ``validation `` middleware if you need to validate the message
2209
- object using the :doc: `Validator component <validator >` before handling it.
2210
- If validation fails, a ``ValidationFailedException `` will be thrown. The
2211
- :class: `Symfony\\ Component\\ Messenger\\ Stamp\\ ValidationStamp ` can be used
2212
- to configure the validation groups.
2213
-
2214
- .. configuration-block ::
2215
-
2216
- .. code-block :: yaml
2217
-
2218
- # config/packages/messenger.yaml
2219
- framework :
2220
- messenger :
2221
- buses :
2222
- command_bus :
2223
- middleware :
2224
- - validation
2225
-
2226
- .. code-block :: xml
2227
-
2228
- <!-- config/packages/messenger.xml -->
2229
- <?xml version =" 1.0" encoding =" UTF-8" ?>
2230
- <container xmlns =" http://symfony.com/schema/dic/services"
2231
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2232
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
2233
- xsi : schemaLocation =" http://symfony.com/schema/dic/services
2234
- https://symfony.com/schema/dic/services/services-1.0.xsd
2235
- http://symfony.com/schema/dic/symfony
2236
- https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
2237
-
2238
- <framework : config >
2239
- <framework : messenger >
2240
- <framework : bus name =" command_bus" >
2241
- <framework : middleware id =" validation" />
2242
- </framework : bus >
2243
- </framework : messenger >
2244
- </framework : config >
2245
- </container >
2246
-
2247
- .. code-block :: php
2248
-
2249
- // config/packages/messenger.php
2250
- $container->loadFromExtension('framework', [
2251
- 'messenger' => [
2252
- 'buses' => [
2253
- 'command_bus' => [
2254
- 'middleware' => [
2255
- 'validation',
2256
- ],
2257
- ],
2258
- ],
2259
- ],
2260
- ]);
2261
-
2262
2209
Messenger Events
2263
2210
~~~~~~~~~~~~~~~~
2264
2211
0 commit comments