| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace DoctrineMigrationsModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     \Zend\EventManager\EventInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Doctrine\ORM\EntityManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class Module | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     public function getConfig() | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         return include __DIR__ . '/../../config/module.config.php'; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function onBootstrap(EventInterface $e) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $application = $e->getTarget(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $events = $application->getEventManager()->getSharedManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $configuration = $application->getServiceManager()->get('doctrine.migrations.configuration'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         // Attach to helper set event and load the entity manager helper. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $sm = $e->getParam('ServiceManager'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             /* @var $cli \Symfony\Component\Console\Application */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $cli = $e->getTarget(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $commands = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 new DiffCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 new ExecuteCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 new GenerateCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 new MigrateCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 new StatusCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 new VersionCommand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             $configuration = $sm->get('doctrine.migrations.configuration'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             foreach($commands AS $command) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 $command->setMigrationConfiguration($configuration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $cli->addCommands($commands); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             /** @var EntityManager $em */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $em = $sm->get('doctrine.entitymanager.orm_default'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $hs = $cli->getHelperSet(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $hs->set(new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), 'em'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $hs->set(new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'db'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $hs->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  |