@@ -104,6 +104,7 @@ public function getConfigTreeBuilder()
104
104
$ this ->addWebLinkSection ($ rootNode );
105
105
$ this ->addLockSection ($ rootNode );
106
106
$ this ->addMessengerSection ($ rootNode );
107
+ $ this ->addAmqpSection ($ rootNode );
107
108
108
109
return $ treeBuilder ;
109
110
}
@@ -1066,4 +1067,152 @@ function ($a) {
1066
1067
->end ()
1067
1068
;
1068
1069
}
1070
+
1071
+ private function addAmqpSection ($ rootNode )
1072
+ {
1073
+ $ rootNode
1074
+ ->children ()
1075
+ ->arrayNode ('amqp ' )
1076
+ ->fixXmlConfig ('connection ' )
1077
+ ->children ()
1078
+ ->arrayNode ('connections ' )
1079
+ ->addDefaultChildrenIfNoneSet ('default ' )
1080
+ ->useAttributeAsKey ('name ' )
1081
+ ->prototype ('array ' )
1082
+ ->fixXmlConfig ('exchange ' )
1083
+ ->fixXmlConfig ('queue ' )
1084
+ ->children ()
1085
+ ->scalarNode ('name ' )
1086
+ ->cannotBeEmpty ()
1087
+ ->end ()
1088
+ ->scalarNode ('dsn ' )
1089
+ ->cannotBeEmpty ()
1090
+ ->defaultValue ('amqp://guest:guest@localhost:5672/symfony ' )
1091
+ ->end ()
1092
+ ->arrayNode ('exchanges ' )
1093
+ ->prototype ('array ' )
1094
+ ->fixXmlConfig ('argument ' )
1095
+ ->children ()
1096
+ ->scalarNode ('name ' )
1097
+ ->isRequired ()
1098
+ ->cannotBeEmpty ()
1099
+ ->end ()
1100
+ ->variableNode ('arguments ' )
1101
+ ->defaultValue (array ())
1102
+ // Deal with XML config
1103
+ ->beforeNormalization ()
1104
+ ->always ()
1105
+ ->then (function ($ v ) {
1106
+ return $ this ->fixXmlArguments ($ v );
1107
+ })
1108
+ ->end ()
1109
+ ->validate ()
1110
+ ->ifTrue (function ($ v ) {
1111
+ return !is_array ($ v );
1112
+ })
1113
+ ->thenInvalid ('Arguments should be an array (got %s). ' )
1114
+ ->end ()
1115
+ ->end ()
1116
+ ->end ()
1117
+ ->end ()
1118
+ ->end ()
1119
+ ->arrayNode ('queues ' )
1120
+ ->prototype ('array ' )
1121
+ ->fixXmlConfig ('argument ' )
1122
+ ->children ()
1123
+ ->scalarNode ('name ' )
1124
+ ->isRequired ()
1125
+ ->cannotBeEmpty ()
1126
+ ->end ()
1127
+ ->variableNode ('arguments ' )
1128
+ ->defaultValue (array ())
1129
+ // Deal with XML config
1130
+ ->beforeNormalization ()
1131
+ ->always ()
1132
+ ->then (function ($ v ) {
1133
+ return $ this ->fixXmlArguments ($ v );
1134
+ })
1135
+ ->end ()
1136
+ ->validate ()
1137
+ ->ifTrue (function ($ v ) {
1138
+ return !is_array ($ v );
1139
+ })
1140
+ ->thenInvalid ('Arguments should be an array (got %s). ' )
1141
+ ->end ()
1142
+ ->end ()
1143
+ ->enumNode ('retry_strategy ' )
1144
+ ->values (array (null , 'constant ' , 'exponential ' ))
1145
+ ->defaultNull ()
1146
+ ->end ()
1147
+ ->variableNode ('retry_strategy_options ' )
1148
+ ->validate ()
1149
+ ->ifTrue (function ($ v ) {
1150
+ return !is_array ($ v );
1151
+ })
1152
+ ->thenInvalid ('Arguments should be an array (got %s). ' )
1153
+ ->end ()
1154
+ ->end ()
1155
+ ->arrayNode ('thresholds ' )
1156
+ ->addDefaultsIfNotSet ()
1157
+ ->children ()
1158
+ ->integerNode ('warning ' )->defaultNull ()->end ()
1159
+ ->integerNode ('critical ' )->defaultNull ()->end ()
1160
+ ->end ()
1161
+ ->end ()
1162
+ ->end ()
1163
+ ->validate ()
1164
+ ->ifTrue (function ($ config ) {
1165
+ return 'constant ' === $ config ['retry_strategy ' ] && !array_key_exists ('max ' , $ config ['retry_strategy_options ' ]);
1166
+ })
1167
+ ->thenInvalid ('"max" of "retry_strategy_options" should be set for constant retry strategy. ' )
1168
+ ->end ()
1169
+ ->validate ()
1170
+ ->ifTrue (function ($ config ) {
1171
+ return 'constant ' === $ config ['retry_strategy ' ] && !array_key_exists ('time ' , $ config ['retry_strategy_options ' ]);
1172
+ })
1173
+ ->thenInvalid ('"time" of "retry_strategy_options" should be set for constant retry strategy. ' )
1174
+ ->end ()
1175
+ ->validate ()
1176
+ ->ifTrue (function ($ config ) {
1177
+ return 'exponential ' === $ config ['retry_strategy ' ] && !array_key_exists ('max ' , $ config ['retry_strategy_options ' ]);
1178
+ })
1179
+ ->thenInvalid ('"max" of "retry_strategy_options" should be set for exponential retry strategy. ' )
1180
+ ->end ()
1181
+ ->validate ()
1182
+ ->ifTrue (function ($ config ) {
1183
+ return 'exponential ' === $ config ['retry_strategy ' ] && !array_key_exists ('offset ' , $ config ['retry_strategy_options ' ]);
1184
+ })
1185
+ ->thenInvalid ('"offset" of "retry_strategy_options" should be set for exponential retry strategy. ' )
1186
+ ->end ()
1187
+ ->end ()
1188
+ ->end ()
1189
+ ->end ()
1190
+ ->end ()
1191
+ ->end ()
1192
+ ->scalarNode ('default_connection ' )
1193
+ ->cannotBeEmpty ()
1194
+ ->end ()
1195
+ ->end ()
1196
+ ->end ()
1197
+ ->end ()
1198
+ ;
1199
+ }
1200
+
1201
+ private function fixXmlArguments ($ v )
1202
+ {
1203
+ if (!is_array ($ v )) {
1204
+ return $ v ;
1205
+ }
1206
+
1207
+ $ tmp = array ();
1208
+
1209
+ foreach ($ v as $ key => $ value ) {
1210
+ if (!isset ($ value ['key ' ]) && !isset ($ value ['value ' ])) {
1211
+ return $ v ;
1212
+ }
1213
+ $ tmp [$ value ['key ' ]] = $ value ['value ' ];
1214
+ }
1215
+
1216
+ return $ tmp ;
1217
+ }
1069
1218
}
0 commit comments