| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ae\FeatureBundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Ae\FeatureBundle\Admin\FeatureAdmin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Config\FileLocator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\DependencyInjection\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\HttpKernel\DependencyInjection\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This is the class that loads and manages your bundle configuration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class AeFeatureExtension extends Extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 18 |  |     public function load(array $configs, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 18 |  |         $loader = new XmlFileLoader( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 18 |  |             $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 18 |  |             new FileLocator(__DIR__.'/../Resources/config') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 18 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 18 |  |         $loader->load('services.xml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 18 |  |         if ($this->canLoadSonataAdmin($container)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 17 |  |             $loader->load('sonata.xml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 17 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 18 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Checks if the Admin class can be loaded without conflicts. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 43 | 18 |  |     private function canLoadSonataAdmin(ContainerBuilder $container) | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 45 | 18 |  |         if (!class_exists('Sonata\AdminBundle\Admin\Admin')) { | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |             return false; | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 49 | 18 |  |         $conflicts = array_filter( | 
            
                                                        
            
                                    
            
            
                | 50 | 18 |  |             $container->getDefinitions(), | 
            
                                                        
            
                                    
            
            
                | 51 | 18 |  |             function (Definition $definition) { | 
            
                                                        
            
                                    
            
            
                | 52 | 18 |  |                 return FeatureAdmin::class === $definition->getClass() && | 
            
                                                        
            
                                    
            
            
                | 53 | 18 |  |                     $definition->hasTag('sonata.admin'); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 55 | 18 |  |         ); | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 57 | 18 |  |         return empty($conflicts); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  |