| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ola\RabbitMqAdminToolkitBundle\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Composer\Script\CommandEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Process\PhpExecutableFinder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Process\Process; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ScriptHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * Define rabbitmq vhost | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @param $event CommandEvent A instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public static function vhostDefine(CommandEvent $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $options = static::getOptions($event); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $consoleDir = static::getConsoleDir($event, 'define rabbitmq vhost'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         if (null === $consoleDir) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $vhost = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         if (!empty($options['vhost'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             $vhost .= $options['vhost']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         static::executeCommand($event, $consoleDir, 'rabbitmq:vhost:define '.$vhost, $options['process-timeout']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected static function executeCommand(CommandEvent $event, $consoleDir, $cmd, $timeout = 300) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $php = escapeshellarg(static::getPhp(false)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $phpArgs = implode(' ', array_map('escapeshellarg', static::getPhpArguments())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $console = escapeshellarg($consoleDir.'/console'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if ($event->getIO()->isDecorated()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $console .= ' --ansi'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $process = new Process($php.($phpArgs ? ' '.$phpArgs : '').' '.$console.' '.$cmd, null, null, null, $timeout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $process->run(function ($type, $buffer) use ($event) { $event->getIO()->write($buffer, false); }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         if (!$process->isSuccessful()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             throw new \RuntimeException(sprintf("An error occurred when executing the \"%s\" command:\n\n%s\n\n%s.", escapeshellarg($cmd), $process->getOutput(), $process->getErrorOutput())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |     protected static function getPhpArguments() | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         $arguments = array(); | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         $phpFinder = new PhpExecutableFinder(); | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         if (method_exists($phpFinder, 'findArguments')) { | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |             $arguments = $phpFinder->findArguments(); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         if (false !== $ini = php_ini_loaded_file()) { | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |             $arguments[] = '--php-ini='.$ini; | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         return $arguments; | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.