@@ -612,26 +612,83 @@ Some third-party bundles and libraries provide configurable middleware via
612
612
factories. Defining such requires a two-step configuration based on Symfony's
613
613
:doc: `dependency injection </service_container >` features:
614
614
<
8000
/td>
615
- .. code-block :: yaml
616
-
617
- services :
618
-
619
- # Step 1: a factory class is registered as a service with the required
620
- # dependencies to instantiate a middleware
621
- doctrine.orm.messenger.middleware_factory.transaction :
622
- class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory
623
- arguments : ['@doctrine']
624
-
625
- # Step 2: an abstract definition that will call the factory with default
626
- # arguments or the ones provided in the middleware config
627
- messenger.middleware.doctrine_transaction_middleware :
628
- class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
629
- factory : ['@doctrine.orm.messenger.middleware_factory.transaction', 'createMiddleware']
630
- abstract : true
631
- # the default arguments to use when none provided from config. Example:
632
- # middleware:
633
- # - doctrine_transaction_middleware: ~
634
- arguments : ['default']
615
+ .. configuration-block ::
616
+
617
+ .. code-block :: yaml
618
+
619
+ # config/services.yaml
620
+ services :
621
+
622
+ # Step 1: a factory class is registered as a service with the required
623
+ # dependencies to instantiate a middleware
624
+ doctrine.orm.messenger.middleware_factory.transaction :
625
+ class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory
626
+ arguments : ['@doctrine']
627
+
628
+ # Step 2: an abstract definition that will call the factory with default
629
+ # arguments or the ones provided in the middleware config
630
+ messenger.middleware.doctrine_transaction_middleware :
631
+ class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
632
+ factory : ' doctrine.orm.messenger.middleware_factory.transaction:createMiddleware'
633
+ abstract : true
634
+ # the default arguments to use when none provided from config. Example:
635
+ # middleware:
636
+ # - doctrine_transaction_middleware: ~
637
+ arguments : ['default']
638
+
639
+ .. code-block :: xml
640
+
641
+ <!-- cconfig/services.xml -->
642
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
643
+ <container xmlns =" http://symfony.com/schema/dic/services"
644
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
645
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
646
+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
647
+
648
+ <services >
649
+ <!-- Step 1: a factory class is registered as a service with the required
650
+ dependencies to instantiate a middleware -->
651
+ <service id =" doctrine.orm.messenger.middleware_factory.transaction"
652
+ class =" Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory" >
653
+
654
+ <argument type =" service" id =" doctrine" />
655
+ </service >
656
+
657
+ <!-- Step 2: an abstract definition that will call the factory with default
658
+ arguments or the ones provided in the middleware config -->
659
+ <service id =" messenger.middleware.doctrine_transaction_middleware"
660
+ class =" Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware"
661
+ abstract =" true" >
662
+
663
+ <factory service =" doctrine.orm.messenger.middleware_factory.transaction"
664
+ method =" createMiddleware" />
665
+ <argument >default</argument >
666
+ </service >
667
+ </services >
668
+ </container >
669
+
670
+ .. code-block :: php
671
+
672
+ // config/services.php
673
+ use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware;
674
+ use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory;
675
+ use Symfony\Component\DependencyInjection\Reference;
676
+
677
+ // Step 1: a factory class is registered as a service with the required
678
+ // dependencies to instantiate a middleware
679
+ $container
680
+ ->register('doctrine.orm.messenger.middleware_factory.transaction', DoctrineTransactionMiddlewareFactory::class)
681
+ ->setArguments(array(new Reference('doctrine')));
682
+
683
+ // Step 2: an abstract definition that will call the factory with default
684
+ // arguments or the ones provided in the middleware config
685
+ $container->register('messenger.middleware.doctrine_transaction_middleware', DoctrineTransactionMiddleware::class)
686
+ ->setFactory(array(
687
+ new Reference('doctrine.orm.messenger.middleware_factory.transaction'),
688
+ 'createMiddleware'
689
+ ))
690
+ ->setAbstract(true)
691
+ ->setArguments(array('default'));
635
692
636
693
The "default" value in this example is the name of the entity manager to use,
637
694
which is the argument expected by the
0 commit comments