| 1 |  |  | <?php namespace League\Tactician\Bundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Symfony\Component\Config\FileLocator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Symfony\Component\DependencyInjection\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\DependencyInjection\Loader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\DependencyInjection\Reference; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class TacticianExtension extends ConfigurableExtension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * Configures the passed container according to the merged configuration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @param array $mergedConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 9 |  |     protected function loadInternal(array $mergedConfig, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 9 |  |         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 9 |  |         $loader->load('services.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 9 |  |         $this->configureCommandBuses($mergedConfig, $container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 9 |  |     public function getAlias() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 9 |  |         return 'tactician'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @param array $mergedConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 9 |  |     private function configureCommandBuses(array $mergedConfig, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 9 |  |         foreach ($mergedConfig['commandbus'] as $commandBusName => $commandBusConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 9 |  |             $middlewares = array_map( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 9 |  |                 function ($middlewareServiceId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 9 |  |                     return new Reference($middlewareServiceId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 9 |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 9 |  |                 $commandBusConfig['middleware'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 9 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 9 |  |             $serviceName = 'tactician.commandbus.' . $commandBusName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 9 |  |             $definition = new Definition($container->getParameter('tactician.commandbus.class'), [$middlewares]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 9 |  |             $container->setDefinition($serviceName, $definition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 9 |  |             if ($commandBusName === $mergedConfig['default_bus']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 9 |  |                 $container->setAlias('tactician.commandbus', $serviceName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 9 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 9 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  |