Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cc05ed2

Browse filesBrowse files
committed
Adding PHP and XML configuration
1 parent c497ed2 commit cc05ed2
Copy full SHA for cc05ed2

File tree

1 file changed

+41
-22
lines changed
Filter options

1 file changed

+41
-22
lines changed

‎messenger/working-with-doctrine.rst

Copy file name to clipboardExpand all lines: messenger/working-with-doctrine.rst
+41-22Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@ writes in a single Doctrine transaction. This make sure that if one of your data
99
query fails, then all queries are rolled back and give you a change to handle the
1010
exception knowing that your database was not changed by your message handler.
1111

12-
To make sure your message bus wraps the handler in one transaction you must first
13-
register the middleware as a service.
14-
15-
.. configuration-block::
16-
17-
.. code-block:: yaml
18-
19-
# config/services.yaml
20-
services:
21-
app.messenger.middleware_factory.transaction:
22-
class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory
23-
arguments: ['@doctrine']
24-
25-
app.doctrine_transaction_middleware:
26-
class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
27-
factory: ['@app.messenger.middleware_factory.transaction', 'createMiddleware']
28-
abstract: true
29-
arguments: ['default']
30-
3112
Next thing you need to do is to add the middleware to your bus configuration.
3213

3314
.. configuration-block::
@@ -37,9 +18,47 @@ Next thing you need to do is to add the middleware to your bus configuration.
3718
# config/packages/messenger.yaml
3819
framework:
3920
# ...
40-
default_bus: messenger.bus.command
4121
buses:
4222
messenger.bus.command:
4323
middleware:
44-
- messenger.middleware.validation
45-
- app.doctrine_transaction_middleware: ['default']
24+
- validation
25+
- doctrine_transaction
26+
27+
.. code-block:: xml
28+
29+
<!-- config/packages/messenger.xml -->
30+
<?xml version="1.0" encoding="UTF-8" ?>
31+
<container xmlns="http://symfony.com/schema/dic/services"
32+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33+
xmlns:framework="http://symfony.com/schema/dic/symfony"
34+
xsi:schemaLocation="http://symfony.com/schema/dic/services
35+
https://symfony.com/schema/dic/services/services-1.0.xsd
36+
http://symfony.com/schema/dic/symfony
37+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
38+
39+
<framework:config>
40+
<framework:messenger>
41+
<framework:bus name="messenger.bus.commands">
42+
<framework:middleware id="validation"/>
43+
<framework:middleware id="doctrine_transaction"/>
44+
<framework:bus>
45+
</framework:messenger>
46+
</framework:config>
47+
</container>
48+
49+
.. code-block:: php
50+
51+
// config/packages/messenger.php
52+
$container->loadFromExtension('framework', [
53+
'messenger' => [
54+
'buses' => [
55+
'messenger.bus.commands' => [
56+
'middleware' => [
57+
'validation',
58+
'doctrine_transaction',
59+
],
60+
],
61+
],
62+
],
63+
]);
64+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.