| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * build a collection_name to routerId mapping for ExtReference Types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This is all done the cheap way by just inferring collection names from | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * the available serviecs that are tagged as rest service. This also means | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * we need to stick to the naming conventions already there even more. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Graviton\DocumentBundle\DependencyInjection\Compiler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Finder\Finder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @license  http://opensource.org/licenses/gpl-license.php GNU Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @link     http://swisscom.ch | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class DocumentMapCompilerPass implements CompilerPassInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * create mapping from services | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param ContainerBuilder $container container builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 30 | 2 |  |     public function process(ContainerBuilder $container) | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |         // If it's inside vendor library or running as graviton base. | 
            
                                                        
            
                                    
            
            
                | 33 | 2 |  |         $rootDir = $container->getParameter('kernel.root_dir'); | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 35 | 2 |  |         if (strpos($rootDir, 'vendor/graviton')) { | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |             $dirs = [ | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |                 $rootDir.'/../..' | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |             ]; | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |             $dirs = [ | 
            
                                                        
            
                                    
            
            
                | 41 | 2 |  |                 __DIR__ . '/../../../..', | 
            
                                                        
            
                                    
            
            
                | 42 | 2 |  |                 $rootDir.'/../vendor/graviton' | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |             ]; | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 46 | 2 |  |         $dynamicBundleDir = $container->getParameter('graviton.generator.dynamicbundle.dir'); | 
            
                                                        
            
                                    
            
            
                | 47 | 2 |  |         if (!empty($dynamicBundleDir)) { | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             $dirs[] = $dynamicBundleDir; | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 51 | 2 |  |         $documentMap = new DocumentMap( | 
            
                                                        
            
                                    
            
            
                | 52 | 2 |  |             (new Finder()) | 
            
                                                        
            
                                    
            
            
                | 53 | 2 |  |                 ->in($dirs) | 
            
                                                        
            
                                    
            
            
                | 54 | 2 |  |                 ->path('Resources/config/doctrine') | 
            
                                                        
            
                                    
            
            
                | 55 | 2 |  |                 ->name('*.mongodb.xml'), | 
            
                                                        
            
                                    
            
            
                | 56 | 2 |  |             (new Finder()) | 
            
                                                        
            
                                    
            
            
                | 57 | 2 |  |                 ->in($dirs) | 
            
                                                        
            
                                    
            
            
                | 58 | 2 |  |                 ->path('Resources/config/serializer') | 
            
                                                        
            
                                    
            
            
                | 59 | 2 |  |                 ->name('*.xml'), | 
            
                                                        
            
                                    
            
            
                | 60 | 2 |  |             (new Finder()) | 
            
                                                        
            
                                    
            
            
                | 61 | 2 |  |                 ->in($dirs) | 
            
                                                        
            
                                    
            
            
                | 62 | 2 |  |                 ->path('Resources/config') | 
            
                                                        
            
                                    
            
            
                | 63 | 2 |  |                 ->name('validation.xml'), | 
            
                                                        
            
                                    
            
            
                | 64 | 2 |  |             (new Finder()) | 
            
                                                        
            
                                    
            
            
                | 65 | 2 |  |                 ->in($dirs) | 
            
                                                        
            
                                    
            
            
                | 66 | 2 |  |                 ->path('Resources/config/schema') | 
            
                                                        
            
                                    
            
            
                | 67 | 2 |  |                 ->name('*.json') | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 70 | 2 |  |         $container->set('graviton.document.map', $documentMap); | 
            
                                                        
            
                                    
            
            
                | 71 | 2 |  |     } | 
            
                                                        
            
                                    
            
            
                | 72 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  |