From e02221571ed4a9a75c28907981f2978b9e30d934 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 11 Jul 2018 10:24:29 +0200 Subject: [PATCH] add XML and PHP code blocks --- messenger.rst | 97 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 20 deletions(-) diff --git a/messenger.rst b/messenger.rst index bd57dfa3a00..d2d8a4b8b0c 100644 --- a/messenger.rst +++ b/messenger.rst @@ -612,26 +612,83 @@ Some third-party bundles and libraries provide configurable middleware via factories. Defining such requires a two-step configuration based on Symfony's :doc:`dependency injection ` features: -.. code-block:: yaml - - services: - - # Step 1: a factory class is registered as a service with the required - # dependencies to instantiate a middleware - doctrine.orm.messenger.middleware_factory.transaction: - class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory - arguments: ['@doctrine'] - - # Step 2: an abstract definition that will call the factory with default - # arguments or the ones provided in the middleware config - messenger.middleware.doctrine_transaction_middleware: - class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware - factory: ['@doctrine.orm.messenger.middleware_factory.transaction', 'createMiddleware'] - abstract: true - # the default arguments to use when none provided from config. Example: - # middleware: - # - doctrine_transaction_middleware: ~ - arguments: ['default'] +.. configuration-block:: + + .. code-block:: yaml + + # config/services.yaml + services: + + # Step 1: a factory class is registered as a service with the required + # dependencies to instantiate a middleware + doctrine.orm.messenger.middleware_factory.transaction: + class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory + arguments: ['@doctrine'] + + # Step 2: an abstract definition that will call the factory with default + # arguments or the ones provided in the middleware config + messenger.middleware.doctrine_transaction_middleware: + class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware + factory: 'doctrine.orm.messenger.middleware_factory.transaction:createMiddleware' + abstract: true + # the default arguments to use when none provided from config. Example: + # middleware: + # - doctrine_transaction_middleware: ~ + arguments: ['default'] + + .. code-block:: xml + + + + + + + + + + + + + + + + + default + + + + + .. code-block:: php + + // config/services.php + use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware; + use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory; + use Symfony\Component\DependencyInjection\Reference; + + // Step 1: a factory class is registered as a service with the required + // dependencies to instantiate a middleware + $container + ->register('doctrine.orm.messenger.middleware_factory.transaction', DoctrineTransactionMiddlewareFactory::class) + ->setArguments(array(new Reference('doctrine'))); + + // Step 2: an abstract definition that will call the factory with default + // arguments or the ones provided in the middleware config + $container->register('messenger.middleware.doctrine_transaction_middleware', DoctrineTransactionMiddleware::class) + ->setFactory(array( + new Reference('doctrine.orm.messenger.middleware_factory.transaction'), + 'createMiddleware' + )) + ->setAbstract(true) + ->setArguments(array('default')); The "default" value in this example is the name of the entity manager to use, which is the argument expected by the