Skip to content

Commit

Permalink
(POC) Update symfony/console 2.x => 3.x
Browse files Browse the repository at this point in the history
This patch updates symfony/console.  A straight update, however, causes a
regression: if you run `php:eval` or `php:script` with an invalid script,
it will no longer have a semantically appropriate error code. Also,
the formatting of the error seems less appropriate.

This patch addresses the exit code (which has more functional impact on
scripting and unit-tests), but I'm kind of surprised that `symfony/console`
went from (v2) reporting the error well to (v3) not reporting the error as
well.  It makes me think that maybe they changed the design and have an
alternative in mind.
  • Loading branch information
totten authored and seamuslee001 committed Dec 8, 2021
1 parent 7a90f5f commit 2ba941e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
74 changes: 49 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\ErrorHandler;

class Application extends \Symfony\Component\Console\Application {

Expand All @@ -12,7 +13,19 @@ class Application extends \Symfony\Component\Console\Application {
*/
public static function main($binDir) {
$application = new Application('cv', '@package_version@');
$application->run();

$application->setAutoExit(FALSE);
$running = TRUE;
register_shutdown_function(function () use (&$running) {
if ($running) {
// Something - like a bad eval() - interrupted normal execution.
// Make sure the status code reflects that.
exit(255);
}
});
$result = $application->run();
$running = FALSE;
exit($result);
}

public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') {
Expand Down

0 comments on commit 2ba941e

Please sign in to comment.