phpsymfonysymfony-console

Early exit from Symfony Console execute()?


I'm using Sympfony Console as a standalone component.

Let's say I've got a Command defined as follows:

class Box extends Command
{
    public function __construct() {
        // removed for simplicity of this example
    }
    protected function configure() {
        // removed for simplicity of this example
    }
    protected function execute(InputInterface $input, OutputInterface $output) {
        if (!$data=\file_get_contents($input->getOption('inputfile'))) { return false;}
        // rest of code removed for simplicity of this example
    }
}

Obviously it is most likely not correct to use return false; So what is the correct way to do it, I can't seem to find a reference or example in the docs ? The nearest thing I can find is a reference to ConsoleEvents::TERMINATE but using events to achive my goal seems a bit overkill ?


Solution

  • I'd say just return as well, don't know why you'd want to do extra fancy stuff to just terminate the command. You could add an output line before the return to tell what's going on in the cli...