| 
                    1
                 | 
                                    
                                                     | 
                
                 | 
                <?php  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    2
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    3
                 | 
                                    
                                                     | 
                
                 | 
                namespace Bankiru\Api\Rpc\DependencyInjection;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    4
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    5
                 | 
                                    
                                                     | 
                
                 | 
                use Bankiru\Api\Rpc\Cache\RouterCacheWarmer;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    6
                 | 
                                    
                                                     | 
                
                 | 
                use Bankiru\Api\Rpc\Listener\RouterListener;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    7
                 | 
                                    
                                                     | 
                
                 | 
                use Bankiru\Api\Rpc\Routing\ResourceMethodCollectionLoader;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    8
                 | 
                                    
                                                     | 
                
                 | 
                use Bankiru\Api\Rpc\Routing\Router;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    9
                 | 
                                    
                                                     | 
                
                 | 
                use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    10
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Bundle\SecurityBundle\SecurityBundle;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    11
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\Config\FileLocator;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    12
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\DependencyInjection\ContainerBuilder;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    13
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\DependencyInjection\Definition;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    14
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\DependencyInjection\Extension\Extension;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    15
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    16
                 | 
                                    
                                                     | 
                
                 | 
                use Symfony\Component\DependencyInjection\Reference;  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    17
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    18
                 | 
                                    
                                                     | 
                
                 | 
                final class BankiruRpcServerExtension extends Extension  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    19
                 | 
                                    
                                                     | 
                
                 | 
                { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    20
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    21
                 | 
                                    
                                                     | 
                
                 | 
                    /** {@inheritdoc} */ | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    22
                 | 
                                    
                             1                          | 
                
                 | 
                    public function load(array $configs, ContainerBuilder $container)  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    23
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    24
                 | 
                                    
                             1                          | 
                
                 | 
                        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    25
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    26
                 | 
                                    
                             1                          | 
                
                 | 
                        $bundles = $container->getParameter('kernel.bundles'); | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    27
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    28
                 | 
                                    
                             1                          | 
                
                 | 
                        $configuration = new Configuration();  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    29
                 | 
                                    
                             1                          | 
                
                 | 
                        $config        = $this->processConfiguration($configuration, $configs);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    30
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    31
                 | 
                                    
                             1                          | 
                
                 | 
                        $loader->load('rpc.yml'); | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    32
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    33
                 | 
                                    
                             1                          | 
                
                 | 
                        if (in_array(SensioFrameworkExtraBundle::class, $bundles, true)) { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    34
                 | 
                                    
                             1                          | 
                
                 | 
                            $loader->load('sensio.yml'); | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    35
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    36
                 | 
                                    
                             1                          | 
                
                 | 
                            if (in_array(SecurityBundle::class, $bundles, true)) { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    37
                 | 
                                    
                             1                          | 
                
                 | 
                                $loader->load('security.yml'); | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    38
                 | 
                                    
                             1                          | 
                
                 | 
                            }  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    39
                 | 
                                    
                             1                          | 
                
                 | 
                        }  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    40
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    41
                 | 
                                    
                             1                          | 
                
                 | 
                        $this->configureRouter($config['router'], $container);  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    42
                 | 
                                    
                             1                          | 
                
                 | 
                    }  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    43
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    44
                 | 
                                    
                             1                          | 
                
                 | 
                    public function getAlias()  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    45
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    46
                 | 
                                    
                             1                          | 
                
                 | 
                        return 'rpc_server';  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    47
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    48
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    49
                 | 
                                    
                                                     | 
                
                 | 
                    /**  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    50
                 | 
                                    
                                                     | 
                
                 | 
                     * @param array            $router  | 
            
            
                                                                                                            
                            
            
                                    
            
            
                | 
                    51
                 | 
                                    
                                                     | 
                
                 | 
                     * @param ContainerBuilder $container  | 
            
            
                                                                                                            
                                                                
            
                                    
            
            
                | 
                    52
                 | 
                                    
                                                     | 
                
                 | 
                     */  | 
            
            
                                                        
            
                                    
            
            
                | 
                    53
                 | 
                                    
                             1                          | 
                
                 | 
                    private function configureRouter(array $router, ContainerBuilder $container)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    54
                 | 
                                    
                                                     | 
                
                 | 
                    { | 
            
            
                                                        
            
                                    
            
            
                | 
                    55
                 | 
                                    
                             1                          | 
                
                 | 
                        $endpoints        = $router['endpoints'];  | 
            
            
                                                        
            
                                    
            
            
                | 
                    56
                 | 
                                    
                             1                          | 
                
                 | 
                        $endpointLoader   = $container->getDefinition('rpc_server.router.loader'); | 
            
            
                                                        
            
                                    
            
            
                | 
                    57
                 | 
                                    
                             1                          | 
                
                 | 
                        $routerCollection = $container->getDefinition('rpc_server.router.collection'); | 
            
            
                                                        
            
                                    
            
            
                | 
                    58
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    59
                 | 
                                    
                             1                          | 
                
                 | 
                        foreach ($endpoints as $name => $config) { | 
            
            
                                                        
            
                                    
            
            
                | 
                    60
                 | 
                                    
                             1                          | 
                
                 | 
                            $routerId = sprintf('rpc_server.endpoint_router.%s', $name); | 
            
            
                                                        
            
                                    
            
            
                | 
                    61
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    62
                 | 
                                    
                             1                          | 
                
                 | 
                            $container->register($routerId, Router::class)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    63
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->setArguments(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    64
                 | 
                                    
                                                     | 
                
                 | 
                                          [  | 
            
            
                                                        
            
                                    
            
            
                | 
                    65
                 | 
                                    
                             1                          | 
                
                 | 
                                              new Definition(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    66
                 | 
                                    
                             1                          | 
                
                 | 
                                                  ResourceMethodCollectionLoader::class,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    67
                 | 
                                    
                                                     | 
                
                 | 
                                                  [  | 
            
            
                                                        
            
                                    
            
            
                | 
                    68
                 | 
                                    
                             1                          | 
                
                 | 
                                                      new Reference('rpc_server.router.resolver'), | 
            
            
                                                        
            
                                    
            
            
                | 
                    69
                 | 
                                    
                             1                          | 
                
                 | 
                                                      $config['resources'],  | 
            
            
                                                        
            
                                    
            
            
                | 
                    70
                 | 
                                    
                             1                          | 
                
                 | 
                                                      $config['context'],  | 
            
            
                                                        
            
                                    
            
            
                | 
                    71
                 | 
                                    
                                                     | 
                
                 | 
                                                  ]  | 
            
            
                                                        
            
                                    
            
            
                | 
                    72
                 | 
                                    
                             1                          | 
                
                 | 
                                              ),  | 
            
            
                                                        
            
                                    
            
            
                | 
                    73
                 | 
                                    
                             1                          | 
                
                 | 
                                              $name,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    74
                 | 
                                    
                                                     | 
                
                 | 
                                              [  | 
            
            
                                                        
            
                                    
            
            
                | 
                    75
                 | 
                                    
                             1                          | 
                
                 | 
                                                  'cache_dir' => '%kernel.cache_dir%',  | 
            
            
                                                        
            
                                    
            
            
                | 
                    76
                 | 
                                    
                             1                          | 
                
                 | 
                                              ],  | 
            
            
                                                        
            
                                    
            
            
                | 
                    77
                 | 
                                    
                                                     | 
                
                 | 
                                          ]  | 
            
            
                                                        
            
                                    
            
            
                | 
                    78
                 | 
                                    
                             1                          | 
                
                 | 
                                      )  | 
            
            
                                                        
            
                                    
            
            
                | 
                    79
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->setPublic(false)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    80
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->addTag('rpc_router'); | 
            
            
                                                        
            
                                    
            
            
                | 
                    81
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    82
                 | 
                                    
                             1                          | 
                
                 | 
                            $container->register(sprintf('rpc_server.router_warmer.%s', $name), RouterCacheWarmer::class) | 
            
            
                                                        
            
                                    
            
            
                | 
                    83
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->setPublic(false)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    84
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->setArguments(  | 
            
            
                                                        
            
                                    
            
            
                | 
                    85
                 | 
                                    
                                                     | 
                
                 | 
                                          [  | 
            
            
                                                        
            
                                    
            
            
                | 
                    86
                 | 
                                    
                             1                          | 
                
                 | 
                                              new Reference($routerId),  | 
            
            
                                                        
            
                                    
            
            
                | 
                    87
                 | 
                                    
                                                     | 
                
                 | 
                                          ]  | 
            
            
                                                        
            
                                    
            
            
                | 
                    88
                 | 
                                    
                             1                          | 
                
                 | 
                                      )  | 
            
            
                                                        
            
                                    
            
            
                | 
                    89
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->addTag('kernel.cache_warmer'); | 
            
            
                                                        
            
                                    
            
            
                | 
                    90
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    91
                 | 
                                    
                             1                          | 
                
                 | 
                            $container->register('rpc_server.router_listener.' . $name, RouterListener::class) | 
            
            
                                                        
            
                                    
            
            
                | 
                    92
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->setArguments([$name, new Reference($routerId)])  | 
            
            
                                                        
            
                                    
            
            
                | 
                    93
                 | 
                                    
                             1                          | 
                
                 | 
                                      ->addTag('kernel.event_listener', ['event' => 'rpc.request', 'method' => 'onRequest']); | 
            
            
                                                        
            
                                    
            
            
                | 
                    94
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    95
                 | 
                                    
                             1                          | 
                
                 | 
                            $endpointLoader->addMethodCall('addEndpoint', [$name, $config]); | 
            
            
                                                        
            
                                    
            
            
                | 
                    96
                 | 
                                    
                             1                          | 
                
                 | 
                            $routerCollection->addMethodCall('addRouter', [$name, new Reference($routerId)]); | 
            
            
                                                        
            
                                    
            
            
                | 
                    97
                 | 
                                    
                             1                          | 
                
                 | 
                        }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    98
                 | 
                                    
                             1                          | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    99
                 | 
                                    
                                                     | 
                
                 | 
                }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    100
                 | 
                                    
                                                     | 
                
                 | 
                 |