2017-12-07 1 views
0

명령 줄에서 실행하는 경우 : php bin/console doctrine : migrations : migrate -n --em = views다른 명령에서 값이 아닌 (InputOption :: VALUE_NONE) 매개 변수와 함께 명령을 호출하려면 어떻게해야합니까?

모든 것이 잘 작동합니다.

그러나 다른 명령에서이 명령을 실행하려고하면 ArrayInput에 InputOption :: VALUE_NONE 매개 변수를 넣는 방법을 모르겠습니다.

private function executeMigrate($connection = null) { 
    $theCommandStr = 'doctrine:migrations:migrate'; 
    $command = $this->getApplication()->find($theCommandStr) ; 
    if ($command) 
    { 
     $arguments = []; 
     $arguments['-n'] = null; //<-- THE PROBLEM IS HERE! 
     $arguments['--em'] = 'views'; 

     $input = new ArrayInput($arguments); 
     $output = new BufferedOutput(); 
     $returnCode = $command->run($input, $output); 

     if($returnCode == 0) { 
      echo "OK"; 
     } else { 
      echo "KO"; 
     } 
    } 
} 

내가 (운없이) 테스트 한 : $ 인수를 [ '- N'] = NULL; $ arguments [ '- n'] = "";

두 옵션을 사용하면 명령이 실행되었지만 -n 수정자가 무시되었습니다.

Symfony v.3.3을 사용하고 있습니다.

답변

0

해결되었습니다. 다른 명령 내부의 명령에 --no-상호 작용 또는 -n 수정을 사용하려는 경우, 당신은 ArrayInput를 사용해야합니다 :: setInteractive 방법 :

이전 코드는 같을 것이다 : 그렇지 않으면

private function executeMigrate($connection = null) { 
    $theCommandStr = 'doctrine:migrations:migrate'; 
    $command = $this->getApplication()->find($theCommandStr) ; 
    if ($command) 
    { 
     $arguments = []; 
     $arguments['--em'] = 'views'; 

     $input = new ArrayInput($arguments); 
     $input->setInteractive(false); 
     $output = new BufferedOutput(); 
     $returnCode = $command->run($input, $output); 

     if($returnCode == 0) { 
      echo "OK"; 
     } else { 
      echo "KO"; 
     } 
    } 
} 

, 그것은 원 일하지 마라.

관련 문제