| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * generator command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace Graviton\GeneratorBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Graviton\GeneratorBundle\Generator\BundleGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sensio\Bundle\GeneratorBundle\Command\GenerateBundleCommand as SymfonyGenerateBundleCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Sensio\Bundle\GeneratorBundle\Model\Bundle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Filesystem\Filesystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\HttpKernel\KernelInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * generator command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @license  http://opensource.org/licenses/gpl-license.php GNU Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @link     http://swisscom.ch | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class GenerateBundleCommand extends SymfonyGenerateBundleCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $loaderBundleName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 18 |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 18 |  |         parent::configure(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 18 |  |         $this->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 18 |  |             'loaderBundleName', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 18 |  |             'lbn', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 18 |  |             InputOption::VALUE_OPTIONAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 18 |  |             'Name of the bundle to manipulate, defaults to GravitonCoreBundle', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 18 |  |             'GravitonCoreBundle' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 18 |  |              ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 18 |  |                  'deleteBefore', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 18 |  |                  'delbef', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 18 |  |                  InputOption::VALUE_OPTIONAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 18 |  |                  'If a string, that directory will be deleted prior to generation', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 18 |  |                  null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |              ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 18 |  |              ->setName('graviton:generate:bundle') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 18 |  |              ->setDescription('Generates a graviton bundle'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 18 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param InputInterface  $input  input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @param OutputInterface $output output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 14 |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 14 |  |         $this->loaderBundleName = $input->getOption('loaderBundleName'); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 | 14 |  |         $deleteBefore = $input->getOption('deleteBefore'); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 14 |  |         $fs = new Filesystem(); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 | 14 |  |         if ($deleteBefore != null && $fs->exists($deleteBefore)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             $fs->remove($deleteBefore); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 14 |  |         parent::execute( | 
            
                                                                        
                            
            
                                    
            
            
                | 77 | 14 |  |             $input, | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 14 |  |             $output | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 | 14 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Add the new bundle to the BundleBundle loader infrastructure instead of main kernel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param OutputInterface $output output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param KernelInterface $kernel kernel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @param Bundle          $bundle bundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @return string[] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     protected function updateKernel(OutputInterface $output, KernelInterface $kernel, Bundle $bundle) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * Don't check routing since graviton bundles usually get routed explicitly based on their naming. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @param OutputInterface $output output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @param Bundle          $bundle bundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 14 |  |     protected function updateRouting(OutputInterface $output, Bundle $bundle) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 14 |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * Don't do anything with the configuration since we load our bundles dynamically using the bundle-bundle-bundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @param OutputInterface $output output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @param Bundle          $bundle bundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 4 |  |     protected function updateConfiguration(OutputInterface $output, Bundle $bundle) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 4 |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * Use an overridden generator to make nicer code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return BundleGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     protected function createGenerator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return new BundleGenerator(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 135 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 136 |  |  |  | 
            
                        
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.