Skip to content

Commit

Permalink
Merge pull request #10346 from dzuelke/errorhandler-php81-compat
Browse files Browse the repository at this point in the history
ErrorHandler PHP 8.1 compatibility
  • Loading branch information
Seldaek committed Dec 9, 2021
2 parents b8e5b1d + be27349 commit da4d937
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/composer
Expand Up @@ -10,6 +10,7 @@ require __DIR__.'/../src/bootstrap.php';

use Composer\Console\Application;
use Composer\XdebugHandler\XdebugHandler;
use Composer\Util\ErrorHandler;

error_reporting(-1);

Expand Down Expand Up @@ -57,6 +58,8 @@ if (function_exists('ini_set')) {

putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0]));

ErrorHandler::register();

// run the command application
$application = new Application();
$application->run();
2 changes: 2 additions & 0 deletions src/Composer/Console/Application.php
Expand Up @@ -127,6 +127,8 @@ public function doRun(InputInterface $input, OutputInterface $output)
$io = $this->io = new ConsoleIO($input, $output, new HelperSet(array(
new QuestionHelper(),
)));

// Register error handler again to pass it the IO instance
ErrorHandler::register($io);

if ($input->hasParameterOption('--no-cache')) {
Expand Down
9 changes: 9 additions & 0 deletions src/Composer/Util/ErrorHandler.php
Expand Up @@ -52,6 +52,15 @@ public static function handle($level, $message, $file, $line)
}

if (self::$io) {
// ignore symfony/* deprecation warnings about return types
// also ignore them from the Composer namespace, as 1.x won't get all that fixed anymore
if (preg_match('{^Return type of (Symfony|Composer)\\\\.*ReturnTypeWillChange}is', $message)) {
return true;
}
if (strpos(strtr($file, '\\', '/'), 'vendor/symfony/') !== false) {
return true;
}

self::$io->writeError('<warning>Deprecation Notice: '.$message.' in '.$file.':'.$line.'</warning>');
if (self::$io->isVerbose()) {
self::$io->writeError('<warning>Stack trace:</warning>');
Expand Down

0 comments on commit da4d937

Please sign in to comment.