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