vendor/prooph/service-bus-symfony-bundle/src/DependencyInjection/Configuration.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * prooph (http://getprooph.org/)
  4.  *
  5.  * @see       https://github.com/prooph/service-bus-symfony-bundle for the canonical source repository
  6.  * @copyright Copyright (c) 2016 prooph software GmbH (http://prooph-software.com/)
  7.  * @license   https://github.com/prooph/service-bus-symfony-bundle/blob/master/LICENSE.md New BSD License
  8.  */
  9. declare(strict_types=1);
  10. namespace Prooph\Bundle\ServiceBus\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. final class Configuration implements ConfigurationInterface
  15. {
  16.     /**
  17.      * Normalizes XML config and defines config tree
  18.      *
  19.      * {@inheritdoc}
  20.      */
  21.     public function getConfigTreeBuilder(): TreeBuilder
  22.     {
  23.         $treeBuilder = new TreeBuilder();
  24.         /** @var ArrayNodeDefinition $rootNode Help phpstan */
  25.         $rootNode $treeBuilder->root('prooph_service_bus');
  26.         foreach (ProophServiceBusExtension::AVAILABLE_BUSES as $type) {
  27.             $this->addServiceBusSection($type$rootNode);
  28.         }
  29.         return $treeBuilder;
  30.     }
  31.     /**
  32.      * Add service bus section to configuration tree
  33.      *
  34.      * @link https://github.com/prooph/service-bus
  35.      *
  36.      * @param string $type Bus type
  37.      * @param ArrayNodeDefinition $node
  38.      */
  39.     private function addServiceBusSection(string $typeArrayNodeDefinition $node): void
  40.     {
  41.         $treeBuilder = new TreeBuilder();
  42.         /** @var ArrayNodeDefinition $routesNode */
  43.         $routesNode $treeBuilder->root('routes');
  44.         $routesNode->useAttributeAsKey($type);
  45.         $handlerNode $routesNode->prototype('event' === $type 'array' 'scalar');
  46.         if ('event' === $type) {
  47.             $handlerNode
  48.                 ->beforeNormalization()
  49.                     ->ifTrue(function ($v) {
  50.                         // XML uses listener nodes
  51.                         return isset($v['listener']);
  52.                     })
  53.                     ->then(function ($v) {
  54.                         // fix single node in XML
  55.                         return (array) $v['listener'];
  56.                     })
  57.                 ->end()
  58.                 ->prototype('scalar')
  59.                     ->beforeNormalization()
  60.                         ->ifTrue(function ($v) {
  61.                             return strpos($v'@') === 0;
  62.                         })
  63.                         ->then(function ($v) {
  64.                             return substr($v1);
  65.                         })
  66.                     ->end()
  67.                 ->end();
  68.         } else {
  69.             $handlerNode
  70.                 ->beforeNormalization()
  71.                     ->ifTrue(function ($v) {
  72.                         return strpos($v'@') === 0;
  73.                     })
  74.                     ->then(function ($v) {
  75.                         return substr($v1);
  76.                     })
  77.                 ->end();
  78.         }
  79.         $handlerNode->end();
  80.         $node
  81.             ->fixXmlConfig($type '_bus'$type '_buses')
  82.             ->children()
  83.             ->arrayNode($type '_buses')
  84.                 ->requiresAtLeastOneElement()
  85.                 ->useAttributeAsKey('name')
  86.                 ->prototype('array')
  87.                 ->fixXmlConfig('plugin''plugins')
  88.                 ->children()
  89.                     ->scalarNode('message_factory')
  90.                         ->beforeNormalization()
  91.                             ->ifTrue(function ($v) {
  92.                                 return strpos($v'@') === 0;
  93.                             })
  94.                             ->then(function ($v) {
  95.                                 return substr($v1);
  96.                             })
  97.                         ->end()
  98.                         ->defaultValue('prooph_service_bus.message_factory')
  99.                     ->end()
  100.                     ->scalarNode('message_data_converter')
  101.                         ->beforeNormalization()
  102.                             ->ifTrue(function ($v) {
  103.                                 return strpos($v'@') === 0;
  104.                             })
  105.                             ->then(function ($v) {
  106.                                 return substr($v1);
  107.                             })
  108.                         ->end()
  109.                         ->defaultValue('prooph_service_bus.message_data_converter.' $type)
  110.                     ->end()
  111.                     ->scalarNode('message_converter')
  112.                         ->beforeNormalization()
  113.                             ->ifTrue(function ($v) {
  114.                                 return strpos($v'@') === 0;
  115.                             })
  116.                             ->then(function ($v) {
  117.                                 return substr($v1);
  118.                             })
  119.                         ->end()
  120.                         ->defaultValue('prooph_service_bus.message_converter')
  121.                     ->end()
  122.                     ->arrayNode('plugins')
  123.                         ->beforeNormalization()
  124.                             // fix single node in XML
  125.                             ->ifString()->then(function ($v) {
  126.                                 return [$v];
  127.                             })
  128.                         ->end()
  129.                         ->prototype('scalar')
  130.                             ->beforeNormalization()
  131.                                 ->ifTrue(function ($v) {
  132.                                     return strpos($v'@') === 0;
  133.                                 })
  134.                                 ->then(function ($v) {
  135.                                     return substr($v1);
  136.                                 })
  137.                             ->end()
  138.                         ->end()
  139.                     ->end()
  140.                     ->arrayNode('router')
  141.                         ->fixXmlConfig('route''routes')
  142.                         ->addDefaultsIfNotSet()
  143.                         ->children()
  144.                             ->scalarNode('type')
  145.                                 ->beforeNormalization()
  146.                                     ->ifTrue(function ($v) {
  147.                                         return strpos($v'@') === 0;
  148.                                     })
  149.                                     ->then(function ($v) {
  150.                                         return substr($v1);
  151.                                     })
  152.                                 ->end()
  153.                                 ->defaultValue('prooph_service_bus.' $type '_bus_router')
  154.                             ->end()
  155.                             ->scalarNode('async_switch')
  156.                                 ->beforeNormalization()
  157.                                     ->ifTrue(function ($v) {
  158.                                         return strpos($v'@') === 0;
  159.                                     })
  160.                                     ->then(function ($v) {
  161.                                         return substr($v1);
  162.                                     })
  163.                                 ->end()
  164.                             ->end()
  165.                             ->append($routesNode)
  166.                         ->end()
  167.                     ->end()
  168.                 ->end()
  169.             ->end();
  170.     }
  171. }