22
33namespace Enqueue \Bundle \DependencyInjection ;
44
5+ use Enqueue \Monitoring \Symfony \DependencyInjection \MonitoringFactory ;
56use Enqueue \Symfony \Client \DependencyInjection \ClientFactory ;
67use Enqueue \Symfony \DependencyInjection \TransportFactory ;
78use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
@@ -26,8 +27,8 @@ public function getConfigTreeBuilder(): TreeBuilder
2627 ->always (function ($ value ) {
2728 if (empty ($ value )) {
2829 return [
29- 'transport ' => [
30- 'default ' => [
30+ 'default ' => [
31+ 'transport ' => [
3132 'dsn ' => 'null: ' ,
3233 ],
3334 ],
@@ -36,8 +37,8 @@ public function getConfigTreeBuilder(): TreeBuilder
3637
3738 if (is_string ($ value )) {
3839 return [
39- 'transport ' => [
40- 'default ' => [
40+ 'default ' => [
41+ 'transport ' => [
4142 'dsn ' => $ value ,
4243 ],
4344 ],
@@ -50,57 +51,82 @@ public function getConfigTreeBuilder(): TreeBuilder
5051
5152 $ transportFactory = new TransportFactory ('default ' );
5253
53- /** @var ArrayNodeDefinition $transportNode */
54- $ transportNode = $ rootNode ->children ()->arrayNode ('transport ' );
55- $ transportNode
56- ->beforeNormalization ()
57- ->always (function ($ value ) {
58- if (empty ($ value )) {
59- return ['default ' => ['dsn ' => 'null: ' ]];
60- }
61- if (is_string ($ value )) {
62- return ['default ' => ['dsn ' => $ value ]];
63- }
64-
65- if (is_array ($ value ) && array_key_exists ('dsn ' , $ value )) {
66- return ['default ' => $ value ];
67- }
68-
69- return $ value ;
70- });
71- $ transportPrototypeNode = $ transportNode
72- ->requiresAtLeastOneElement ()
73- ->useAttributeAsKey ('key ' )
74- ->prototype ('array ' )
75- ;
54+ $ transportConfig = $ transportFactory ->getConfiguration ('transport ' );
55+ $ transportConfig ->isRequired ();
7656
77- $ transportFactory ->addTransportConfiguration ( $ transportPrototypeNode );
57+ $ consumerConfig = $ transportFactory ->getQueueConsumerConfiguration ( ' consumption ' );
7858
79- $ consumptionNode = $ rootNode ->children ()->arrayNode ('consumption ' );
80- $ transportFactory ->addQueueConsumerConfiguration ($ consumptionNode );
59+ $ clientConfig = (new ClientFactory ('default ' ))->getConfiguration ('client ' , $ this ->debug );
8160
82- $ clientFactory = new ClientFactory ('default ' );
83- $ clientNode = $ rootNode ->children ()->arrayNode ('client ' );
84- $ clientFactory ->addClientConfiguration ($ clientNode , $ this ->debug );
61+ $ monitoringConfig = (new MonitoringFactory ('default ' ))->getConfiguration ('monitoring ' );
8562
86- $ rootNode ->children ()
87- ->booleanNode ('job ' )->defaultFalse ()->end ()
88- ->arrayNode ('async_events ' )
89- ->addDefaultsIfNotSet ()
90- ->canBeEnabled ()
91- ->end ()
92- ->arrayNode ('async_commands ' )
93- ->addDefaultsIfNotSet ()
94- ->canBeEnabled ()
63+ $ rootNode
64+ ->requiresAtLeastOneElement ()
65+ ->useAttributeAsKey ('key ' )
66+ ->arrayPrototype ()
67+ ->children ()
68+ ->append ($ transportConfig )
69+ ->append ($ consumerConfig )
70+ ->append ($ clientConfig )
71+ ->append ($ monitoringConfig )
72+ ->end ()
9573 ->end ()
96- ->arrayNode ('extensions ' )->addDefaultsIfNotSet ()->children ()
97- ->booleanNode ('doctrine_ping_connection_extension ' )->defaultFalse ()->end ()
98- ->booleanNode ('doctrine_clear_identity_map_extension ' )->defaultFalse ()->end ()
99- ->booleanNode ('signal_extension ' )->defaultValue (function_exists ('pcntl_signal_dispatch ' ))->end ()
100- ->booleanNode ('reply_extension ' )->defaultTrue ()->end ()
101- ->end ()->end ()
10274 ;
10375
76+
77+ // $transportFactory = new TransportFactory('default');
78+ //
79+ // /** @var ArrayNodeDefinition $transportNode */
80+ // $transportNode = $rootNode->children()->arrayNode('transport');
81+ // $transportNode
82+ // ->beforeNormalization()
83+ // ->always(function ($value) {
84+ // if (empty($value)) {
85+ // return ['default' => ['dsn' => 'null:']];
86+ // }
87+ // if (is_string($value)) {
88+ // return ['default' => ['dsn' => $value]];
89+ // }
90+ //
91+ // if (is_array($value) && array_key_exists('dsn', $value)) {
92+ // return ['default' => $value];
93+ // }
94+ //
95+ // return $value;
96+ // });
97+ // $transportPrototypeNode = $transportNode
98+ // ->requiresAtLeastOneElement()
99+ // ->useAttributeAsKey('key')
100+ // ->prototype('array')
101+ // ;
102+ //
103+ // $transportFactory->addTransportConfiguration($transportPrototypeNode);
104+ //
105+ // $consumptionNode = $rootNode->children()->arrayNode('consumption');
106+ // $transportFactory->addQueueConsumerConfiguration($consumptionNode);
107+ //
108+ // $clientFactory = new ClientFactory('default');
109+ // $clientNode = $rootNode->children()->arrayNode('client');
110+ // $clientFactory->addClientConfiguration($clientNode, $this->debug);
111+ //
112+ // $rootNode->children()
113+ // ->booleanNode('job')->defaultFalse()->end()
114+ // ->arrayNode('async_events')
115+ // ->addDefaultsIfNotSet()
116+ // ->canBeEnabled()
117+ // ->end()
118+ // ->arrayNode('async_commands')
119+ // ->addDefaultsIfNotSet()
120+ // ->canBeEnabled()
121+ // ->end()
122+ // ->arrayNode('extensions')->addDefaultsIfNotSet()->children()
123+ // ->booleanNode('doctrine_ping_connection_extension')->defaultFalse()->end()
124+ // ->booleanNode('doctrine_clear_identity_map_extension')->defaultFalse()->end()
125+ // ->booleanNode('signal_extension')->defaultValue(function_exists('pcntl_signal_dispatch'))->end()
126+ // ->booleanNode('reply_extension')->defaultTrue()->end()
127+ // ->end()->end()
128+ // ;
129+ //
104130 return $ tb ;
105131 }
106132}
0 commit comments