所有命令的返回结果在类Symfony\Component\Console\Command\Command
、方法run
中定义:
return is_numeric($statusCode) ? (int) $statusCode : 0;
The $statusCode
variable is set by calling the command's execute
method, which in artisan's case is defined in the class Illuminate\Console\Command
:
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->fire();
}
The result of the fire
method is left up to the individual commands, in the case of php artisan migrate
command, nothing is returned from the method so the $statusCode
is null (which is why you get the 0 returned from Symfony\Component\Console\Command\Command::run
method)
如果想从自定义命令返回响应,只需从fire
方法返回一个整数,它就会跳回$statusCode
.您可以使用它以编程方式根据自定义命令的不同结果进行切换.
If you specifically want to get the result from the artisan:migrate
command, then I don't think there's much you can do to change the return value besides wrapping the command in your own custom command that calls it.