Skip to content

Commit

Permalink
Handle commands that dump something
Browse files Browse the repository at this point in the history
The idea is to catch the dumped result via ob_* functions, and consider it as the output of the command.
  • Loading branch information
winzou committed Feb 21, 2013
1 parent 63522b0 commit 86ab2cf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Controller/ConsoleController.php
Expand Up @@ -77,11 +77,19 @@ protected function executeCommand($command)

$application = $this->getApplication($input);
$application->setAutoExit(false);

// Some commands (i.e. doctrine:query:dql) dump things out instead of returning a value
ob_start();
$errorCode = $application->run($input, $output);
// So, if the returned output is empty
if (!$result = $output->getBuffer()) {
$result = ob_get_contents(); // We replace it by the catched output
}
ob_end_clean();

return array(
'input' => $command,
'output' => $output->getBuffer(),
'output' => $result,
'environment' => $this->getKernel($input)->getEnvironment(),
'error_code' => $errorCode
);
Expand Down

0 comments on commit 86ab2cf

Please sign in to comment.