| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* (c) Anton Medvedev <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Deployer\Console; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Deployer\Collection\PersistentCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Deployer\Deployer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Deployer\Exception\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Deployer\Exception\GracefulShutdownException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Deployer\Exception\NonFatalException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Deployer\Task\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Input\InputOption as Option; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class WorkerCommand extends MainCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct(Deployer $deployer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         parent::__construct('worker', null, $deployer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->setHidden(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     protected function configure() | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $this->addArgument('worker-task', InputArgument::REQUIRED); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         $this->addArgument('worker-host', InputArgument::REQUIRED); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         $this->addArgument('config-directory', InputArgument::REQUIRED); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->addArgument('original-task', InputArgument::REQUIRED); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $this->addOption('decorated', null, Option::VALUE_NONE); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         parent::configure(); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $output->setDecorated($input->getOption('decorated')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         if (!$output->isDecorated()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             define('NO_ANSI', 'true'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $host = $this->deployer->hosts->get($input->getArgument('worker-host')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $task = $this->deployer->tasks->get($input->getArgument('worker-task')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->deployer->config->set('config_directory', $input->getArgument('config-directory')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $host->getConfig()->load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         foreach ($host->getConfig() as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $this->deployer->config->set($name, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             Exception::setTaskSourceLocation($task->getSourceLocation()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $task->run(new Context($host, $input, $output)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $this->deployer->messenger->endOnHost($host); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $host->getConfig()->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } catch (GracefulShutdownException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $this->deployer->messenger->renderException($e, $host); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             return GracefulShutdownException::EXIT_CODE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } catch (\Throwable $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             $this->deployer->messenger->renderException($e, $host); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             return 255; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |  | 
            
                        
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.