eMAGTechLabs /
RabbitMqBundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace OldSound\RabbitMqBundle\DependencyInjection; |
||
| 4 | |||
| 5 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
| 6 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
| 7 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Configuration |
||
| 11 | * |
||
| 12 | * @author Marc Weistroff <[email protected]> |
||
| 13 | */ |
||
| 14 | class Configuration implements ConfigurationInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $name; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Configuration constructor. |
||
| 23 | * |
||
| 24 | * @param string $name |
||
| 25 | */ |
||
| 26 | public function __construct($name) |
||
| 27 | { |
||
| 28 | $this->name = $name; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getConfigTreeBuilder() |
||
| 32 | { |
||
| 33 | $tree = new TreeBuilder($this->name); |
||
| 34 | /** @var ArrayNodeDefinition $rootNode */ |
||
| 35 | $rootNode = $tree->getRootNode(); |
||
| 36 | |||
| 37 | $rootNode |
||
| 38 | ->children() |
||
| 39 | ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() |
||
| 40 | ->booleanNode('enable_collector')->defaultValue(false)->end() |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | ->booleanNode('sandbox')->defaultValue(false)->end() |
||
| 42 | ->end() |
||
| 43 | ; |
||
| 44 | |||
| 45 | $this->addConnections($rootNode); |
||
| 46 | $this->addBindings($rootNode); |
||
| 47 | $this->addProducers($rootNode); |
||
| 48 | $this->addConsumers($rootNode); |
||
| 49 | $this->addMultipleConsumers($rootNode); |
||
| 50 | $this->addDynamicConsumers($rootNode); |
||
| 51 | $this->addBatchConsumers($rootNode); |
||
| 52 | $this->addAnonConsumers($rootNode); |
||
| 53 | $this->addRpcClients($rootNode); |
||
| 54 | $this->addRpcServers($rootNode); |
||
| 55 | |||
| 56 | return $tree; |
||
| 57 | } |
||
| 58 | |||
| 59 | protected function addConnections(ArrayNodeDefinition $node) |
||
| 60 | { |
||
| 61 | $node |
||
| 62 | ->fixXmlConfig('connection') |
||
| 63 | ->children() |
||
| 64 | ->arrayNode('connections') |
||
| 65 | ->useAttributeAsKey('key') |
||
| 66 | ->canBeUnset() |
||
| 67 | ->prototype('array') |
||
| 68 | ->children() |
||
| 69 | ->scalarNode('url')->defaultValue('')->end() |
||
| 70 | ->scalarNode('host')->defaultValue('localhost')->end() |
||
| 71 | ->scalarNode('port')->defaultValue(5672)->end() |
||
| 72 | ->scalarNode('user')->defaultValue('guest')->end() |
||
| 73 | ->scalarNode('password')->defaultValue('guest')->end() |
||
| 74 | ->scalarNode('vhost')->defaultValue('/')->end() |
||
| 75 | ->booleanNode('lazy')->defaultFalse()->end() |
||
| 76 | ->scalarNode('connection_timeout')->defaultValue(3)->end() |
||
| 77 | ->scalarNode('read_write_timeout')->defaultValue(3)->end() |
||
| 78 | ->booleanNode('use_socket')->defaultValue(false)->end() |
||
| 79 | ->arrayNode('ssl_context') |
||
| 80 | ->useAttributeAsKey('key') |
||
| 81 | ->canBeUnset() |
||
| 82 | ->prototype('variable')->end() |
||
| 83 | ->end() |
||
| 84 | ->booleanNode('keepalive')->defaultFalse()->info('requires php-amqplib v2.4.1+ and PHP5.4+')->end() |
||
| 85 | ->scalarNode('heartbeat')->defaultValue(0)->info('requires php-amqplib v2.4.1+')->end() |
||
| 86 | ->scalarNode('connection_parameters_provider')->end() |
||
| 87 | ->end() |
||
| 88 | ->end() |
||
| 89 | ->end() |
||
| 90 | ->end() |
||
| 91 | ; |
||
| 92 | } |
||
| 93 | |||
| 94 | protected function addProducers(ArrayNodeDefinition $node) |
||
| 95 | { |
||
| 96 | $node |
||
| 97 | ->fixXmlConfig('producer') |
||
| 98 | ->children() |
||
| 99 | ->arrayNode('producers') |
||
| 100 | ->canBeUnset() |
||
| 101 | ->useAttributeAsKey('key') |
||
| 102 | ->prototype('array') |
||
| 103 | ->append($this->getExchangeConfiguration()) |
||
| 104 | ->append($this->getQueueConfiguration()) |
||
| 105 | ->children() |
||
| 106 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 107 | ->scalarNode('auto_setup_fabric')->defaultTrue()->end() |
||
| 108 | ->scalarNode('class')->defaultValue('%old_sound_rabbit_mq.producer.class%')->end() |
||
| 109 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 110 | ->scalarNode('service_alias')->defaultValue(null)->end() |
||
| 111 | ->end() |
||
| 112 | ->end() |
||
| 113 | ->end() |
||
| 114 | ->end() |
||
| 115 | ; |
||
| 116 | } |
||
| 117 | |||
| 118 | protected function addBindings(ArrayNodeDefinition $node) |
||
| 119 | { |
||
| 120 | $node |
||
| 121 | ->fixXmlConfig('binding') |
||
| 122 | ->children() |
||
| 123 | ->arrayNode('bindings') |
||
| 124 | ->canBeUnset() |
||
| 125 | ->prototype('array') |
||
| 126 | ->children() |
||
| 127 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 128 | ->scalarNode('exchange')->defaultNull()->end() |
||
| 129 | ->scalarNode('destination')->defaultNull()->end() |
||
| 130 | ->scalarNode('routing_key')->defaultNull()->end() |
||
| 131 | ->booleanNode('nowait')->defaultFalse()->end() |
||
| 132 | ->booleanNode('destination_is_exchange')->defaultFalse()->end() |
||
| 133 | ->variableNode('arguments')->defaultNull()->end() |
||
| 134 | ->scalarNode('class')->defaultValue('%old_sound_rabbit_mq.binding.class%')->end() |
||
| 135 | ->end() |
||
| 136 | ->end() |
||
| 137 | ->end() |
||
| 138 | ->end() |
||
| 139 | ; |
||
| 140 | } |
||
| 141 | |||
| 142 | protected function addConsumers(ArrayNodeDefinition $node) |
||
| 143 | { |
||
| 144 | $node |
||
| 145 | ->fixXmlConfig('consumer') |
||
| 146 | ->children() |
||
| 147 | ->arrayNode('consumers') |
||
| 148 | ->canBeUnset() |
||
| 149 | ->useAttributeAsKey('key') |
||
| 150 | ->prototype('array') |
||
| 151 | ->append($this->getExchangeConfiguration()) |
||
| 152 | ->append($this->getQueueConfiguration()) |
||
| 153 | ->children() |
||
| 154 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 155 | ->scalarNode('callback')->isRequired()->end() |
||
| 156 | ->scalarNode('idle_timeout')->end() |
||
| 157 | ->scalarNode('idle_timeout_exit_code')->end() |
||
| 158 | ->arrayNode('graceful_max_execution') |
||
| 159 | ->canBeUnset() |
||
| 160 | ->children() |
||
| 161 | ->integerNode('timeout')->end() |
||
| 162 | ->integerNode('exit_code')->defaultValue(0)->end() |
||
| 163 | ->end() |
||
| 164 | ->end() |
||
| 165 | ->scalarNode('auto_setup_fabric')->defaultTrue()->end() |
||
| 166 | ->arrayNode('qos_options') |
||
| 167 | ->canBeUnset() |
||
| 168 | ->children() |
||
| 169 | ->scalarNode('prefetch_size')->defaultValue(0)->end() |
||
| 170 | ->scalarNode('prefetch_count')->defaultValue(0)->end() |
||
| 171 | ->booleanNode('global')->defaultFalse()->end() |
||
| 172 | ->end() |
||
| 173 | ->end() |
||
| 174 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 175 | ->end() |
||
| 176 | ->end() |
||
| 177 | ->end() |
||
| 178 | ->end() |
||
| 179 | ; |
||
| 180 | } |
||
| 181 | |||
| 182 | protected function addMultipleConsumers(ArrayNodeDefinition $node) |
||
| 183 | { |
||
| 184 | $node |
||
| 185 | ->fixXmlConfig('multiple_consumer') |
||
| 186 | ->children() |
||
| 187 | ->arrayNode('multiple_consumers') |
||
| 188 | ->canBeUnset() |
||
| 189 | ->useAttributeAsKey('key') |
||
| 190 | ->prototype('array') |
||
| 191 | ->append($this->getExchangeConfiguration()) |
||
| 192 | ->children() |
||
| 193 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 194 | ->scalarNode('idle_timeout')->end() |
||
| 195 | ->scalarNode('idle_timeout_exit_code')->end() |
||
| 196 | ->scalarNode('auto_setup_fabric')->defaultTrue()->end() |
||
| 197 | ->arrayNode('graceful_max_execution') |
||
| 198 | ->canBeUnset() |
||
| 199 | ->children() |
||
| 200 | ->integerNode('timeout')->end() |
||
| 201 | ->integerNode('exit_code')->defaultValue(0)->end() |
||
| 202 | ->end() |
||
| 203 | ->end() |
||
| 204 | ->append($this->getMultipleQueuesConfiguration()) |
||
| 205 | ->arrayNode('qos_options') |
||
| 206 | ->canBeUnset() |
||
| 207 | ->children() |
||
| 208 | ->scalarNode('prefetch_size')->defaultValue(0)->end() |
||
| 209 | ->scalarNode('prefetch_count')->defaultValue(0)->end() |
||
| 210 | ->booleanNode('global')->defaultFalse()->end() |
||
| 211 | ->end() |
||
| 212 | ->end() |
||
| 213 | ->scalarNode('queues_provider')->defaultNull()->end() |
||
| 214 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 215 | ->end() |
||
| 216 | ->end() |
||
| 217 | ->end() |
||
| 218 | ; |
||
| 219 | } |
||
| 220 | |||
| 221 | protected function addDynamicConsumers(ArrayNodeDefinition $node) |
||
| 222 | { |
||
| 223 | $node |
||
| 224 | ->fixXmlConfig('dynamic_consumer') |
||
| 225 | ->children() |
||
| 226 | ->arrayNode('dynamic_consumers') |
||
| 227 | ->canBeUnset() |
||
| 228 | ->useAttributeAsKey('key') |
||
| 229 | ->prototype('array') |
||
| 230 | ->append($this->getExchangeConfiguration()) |
||
| 231 | ->children() |
||
| 232 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 233 | ->scalarNode('callback')->isRequired()->end() |
||
| 234 | ->scalarNode('idle_timeout')->end() |
||
| 235 | ->scalarNode('idle_timeout_exit_code')->end() |
||
| 236 | ->arrayNode('graceful_max_execution') |
||
| 237 | ->canBeUnset() |
||
| 238 | ->children() |
||
| 239 | ->integerNode('timeout')->end() |
||
| 240 | ->integerNode('exit_code')->defaultValue(0)->end() |
||
| 241 | ->end() |
||
| 242 | ->end() |
||
| 243 | ->scalarNode('auto_setup_fabric')->defaultTrue()->end() |
||
| 244 | ->arrayNode('qos_options') |
||
| 245 | ->canBeUnset() |
||
| 246 | ->children() |
||
| 247 | ->scalarNode('prefetch_size')->defaultValue(0)->end() |
||
| 248 | ->scalarNode('prefetch_count')->defaultValue(0)->end() |
||
| 249 | ->booleanNode('global')->defaultFalse()->end() |
||
| 250 | ->end() |
||
| 251 | ->end() |
||
| 252 | ->scalarNode('queue_options_provider')->isRequired()->end() |
||
| 253 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 254 | ->end() |
||
| 255 | ->end() |
||
| 256 | ->end() |
||
| 257 | ->end() |
||
| 258 | ; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param ArrayNodeDefinition $node |
||
| 263 | * |
||
| 264 | * @return void |
||
| 265 | */ |
||
| 266 | protected function addBatchConsumers(ArrayNodeDefinition $node) |
||
| 267 | { |
||
| 268 | $node |
||
| 269 | ->children() |
||
| 270 | ->arrayNode('batch_consumers') |
||
| 271 | ->canBeUnset() |
||
| 272 | ->useAttributeAsKey('key') |
||
| 273 | ->prototype('array') |
||
| 274 | ->append($this->getExchangeConfiguration()) |
||
| 275 | ->append($this->getQueueConfiguration()) |
||
| 276 | ->children() |
||
| 277 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 278 | ->scalarNode('callback')->isRequired()->end() |
||
| 279 | ->scalarNode('idle_timeout')->end() |
||
| 280 | ->scalarNode('timeout_wait')->defaultValue(3)->end() |
||
| 281 | ->scalarNode('idle_timeout_exit_code')->end() |
||
| 282 | ->scalarNode('keep_alive')->defaultFalse()->end() |
||
| 283 | ->arrayNode('graceful_max_execution') |
||
| 284 | ->canBeUnset() |
||
| 285 | ->children() |
||
| 286 | ->integerNode('timeout')->end() |
||
| 287 | ->end() |
||
| 288 | ->end() |
||
| 289 | ->scalarNode('auto_setup_fabric')->defaultTrue()->end() |
||
| 290 | ->arrayNode('qos_options') |
||
| 291 | ->children() |
||
| 292 | ->scalarNode('prefetch_size')->defaultValue(0)->end() |
||
| 293 | ->scalarNode('prefetch_count')->defaultValue(2)->end() |
||
| 294 | ->booleanNode('global')->defaultFalse()->end() |
||
| 295 | ->end() |
||
| 296 | ->end() |
||
| 297 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 298 | ->end() |
||
| 299 | ->end() |
||
| 300 | ->end() |
||
| 301 | ->end() |
||
| 302 | ; |
||
| 303 | } |
||
| 304 | |||
| 305 | protected function addAnonConsumers(ArrayNodeDefinition $node) |
||
| 306 | { |
||
| 307 | $node |
||
| 308 | ->fixXmlConfig('anon_consumer') |
||
| 309 | ->children() |
||
| 310 | ->arrayNode('anon_consumers') |
||
| 311 | ->canBeUnset() |
||
| 312 | ->useAttributeAsKey('key') |
||
| 313 | ->prototype('array') |
||
| 314 | ->append($this->getExchangeConfiguration()) |
||
| 315 | ->children() |
||
| 316 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 317 | ->scalarNode('callback')->isRequired()->end() |
||
| 318 | ->end() |
||
| 319 | ->end() |
||
| 320 | ->end() |
||
| 321 | ->end() |
||
| 322 | ; |
||
| 323 | } |
||
| 324 | |||
| 325 | protected function addRpcClients(ArrayNodeDefinition $node) |
||
| 326 | { |
||
| 327 | $node |
||
| 328 | ->fixXmlConfig('rpc_client') |
||
| 329 | ->children() |
||
| 330 | ->arrayNode('rpc_clients') |
||
| 331 | ->canBeUnset() |
||
| 332 | ->useAttributeAsKey('key') |
||
| 333 | ->prototype('array') |
||
| 334 | ->children() |
||
| 335 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 336 | ->booleanNode('expect_serialized_response')->defaultTrue()->end() |
||
| 337 | ->scalarNode('unserializer')->defaultValue('unserialize')->end() |
||
| 338 | ->booleanNode('lazy')->defaultFalse()->end() |
||
| 339 | ->booleanNode('direct_reply_to')->defaultFalse()->end() |
||
| 340 | ->end() |
||
| 341 | ->end() |
||
| 342 | ->end() |
||
| 343 | ->end() |
||
| 344 | ; |
||
| 345 | } |
||
| 346 | |||
| 347 | protected function addRpcServers(ArrayNodeDefinition $node) |
||
| 348 | { |
||
| 349 | $node |
||
| 350 | ->fixXmlConfig('rpc_server') |
||
| 351 | ->children() |
||
| 352 | ->arrayNode('rpc_servers') |
||
| 353 | ->canBeUnset() |
||
| 354 | ->useAttributeAsKey('key') |
||
| 355 | ->prototype('array') |
||
| 356 | ->append($this->getExchangeConfiguration()) |
||
| 357 | ->append($this->getQueueConfiguration()) |
||
| 358 | ->children() |
||
| 359 | ->scalarNode('connection')->defaultValue('default')->end() |
||
| 360 | ->scalarNode('callback')->isRequired()->end() |
||
| 361 | ->arrayNode('qos_options') |
||
| 362 | ->canBeUnset() |
||
| 363 | ->children() |
||
| 364 | ->scalarNode('prefetch_size')->defaultValue(0)->end() |
||
| 365 | ->scalarNode('prefetch_count')->defaultValue(0)->end() |
||
| 366 | ->booleanNode('global')->defaultFalse()->end() |
||
| 367 | ->end() |
||
| 368 | ->end() |
||
| 369 | ->scalarNode('serializer')->defaultValue('serialize')->end() |
||
| 370 | ->scalarNode('enable_logger')->defaultFalse()->end() |
||
| 371 | ->end() |
||
| 372 | ->end() |
||
| 373 | ->end() |
||
| 374 | ->end() |
||
| 375 | ; |
||
| 376 | } |
||
| 377 | |||
| 378 | protected function getExchangeConfiguration() |
||
| 379 | { |
||
| 380 | $node = new ArrayNodeDefinition('exchange_options'); |
||
| 381 | |||
| 382 | return $node |
||
| 383 | ->children() |
||
| 384 | ->scalarNode('name')->isRequired()->end() |
||
| 385 | ->scalarNode('type')->isRequired()->end() |
||
| 386 | ->booleanNode('passive')->defaultValue(false)->end() |
||
| 387 | ->booleanNode('durable')->defaultValue(true)->end() |
||
| 388 | ->booleanNode('auto_delete')->defaultValue(false)->end() |
||
| 389 | ->booleanNode('internal')->defaultValue(false)->end() |
||
| 390 | ->booleanNode('nowait')->defaultValue(false)->end() |
||
| 391 | ->booleanNode('declare')->defaultValue(true)->end() |
||
| 392 | ->variableNode('arguments')->defaultNull()->end() |
||
| 393 | ->scalarNode('ticket')->defaultNull()->end() |
||
| 394 | ->end() |
||
| 395 | ; |
||
| 396 | } |
||
| 397 | |||
| 398 | protected function getQueueConfiguration() |
||
| 399 | { |
||
| 400 | $node = new ArrayNodeDefinition('queue_options'); |
||
| 401 | |||
| 402 | $this->addQueueNodeConfiguration($node); |
||
| 403 | |||
| 404 | return $node; |
||
| 405 | } |
||
| 406 | |||
| 407 | protected function getMultipleQueuesConfiguration() |
||
| 408 | { |
||
| 409 | $node = new ArrayNodeDefinition('queues'); |
||
| 410 | $prototypeNode = $node->prototype('array'); |
||
| 411 | |||
| 412 | $this->addQueueNodeConfiguration($prototypeNode); |
||
| 413 | |||
| 414 | $prototypeNode->children() |
||
| 415 | ->scalarNode('callback')->isRequired()->end() |
||
| 416 | ->end(); |
||
| 417 | |||
| 418 | $prototypeNode->end(); |
||
| 419 | |||
| 420 | return $node; |
||
| 421 | } |
||
| 422 | |||
| 423 | protected function addQueueNodeConfiguration(ArrayNodeDefinition $node) |
||
| 424 | { |
||
| 425 | $node |
||
| 426 | ->fixXmlConfig('routing_key') |
||
| 427 | ->children() |
||
| 428 | ->scalarNode('name')->end() |
||
| 429 | ->booleanNode('passive')->defaultFalse()->end() |
||
| 430 | ->booleanNode('durable')->defaultTrue()->end() |
||
| 431 | ->booleanNode('exclusive')->defaultFalse()->end() |
||
| 432 | ->booleanNode('auto_delete')->defaultFalse()->end() |
||
| 433 | ->booleanNode('nowait')->defaultFalse()->end() |
||
| 434 | ->booleanNode('declare')->defaultTrue()->end() |
||
| 435 | ->variableNode('arguments')->defaultNull()->end() |
||
| 436 | ->scalarNode('ticket')->defaultNull()->end() |
||
| 437 | ->arrayNode('routing_keys') |
||
| 438 | ->prototype('scalar')->end() |
||
| 439 | ->defaultValue(array()) |
||
| 440 | ->end() |
||
| 441 | ->end() |
||
| 442 | ; |
||
| 443 | } |
||
| 444 | } |
||
| 445 |