1
0
Fork 0

Handle deprecation notices softer

pull/4091/head
Jordi Boggiano 2015-05-31 12:26:17 +01:00
parent e64470c987
commit 1753c275ff
2 changed files with 23 additions and 3 deletions

View File

@ -65,7 +65,6 @@ class Application extends BaseApplication
date_default_timezone_set(@date_default_timezone_get());
}
ErrorHandler::register();
parent::__construct('Composer', Composer::VERSION);
}
@ -89,6 +88,7 @@ class Application extends BaseApplication
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
ErrorHandler::register($this->io);
if (PHP_VERSION_ID < 50302) {
$this->getIO()->writeError('<warning>Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.</warning>');

View File

@ -12,6 +12,8 @@
namespace Composer\Util;
use Composer\IO\IOInterface;
/**
* Convert PHP errors into exceptions
*
@ -19,6 +21,8 @@ namespace Composer\Util;
*/
class ErrorHandler
{
private static $io;
/**
* Error handler
*
@ -42,16 +46,32 @@ class ErrorHandler
"\na legitimately suppressed error that you were not supposed to see.";
}
if ($level !== E_DEPRECATED && $level !== E_USER_DEPRECATED) {
throw new \ErrorException($message, 0, $level, $file, $line);
}
if (self::$io) {
self::$io->writeError('<warning>Deprecation Notice: '.$message.' in '.$file.':'.$line.'</warning>');
if (self::$io->isVerbose()) {
self::$io->writeError('<warning>Stack trace:</warning>');
self::$io->writeError(array_filter(array_map(function ($a) {
if (isset($a['line'], $a['file'])) {
return '<warning> '.$a['file'].':'.$a['line'].'</warning>';
}
return null;
}, array_slice(debug_backtrace(), 2))));
}
}
}
/**
* Register error handler
*
* @static
*/
public static function register()
public static function register(IOInterface $io = null)
{
set_error_handler(array(__CLASS__, 'handle'));
self::$io = $io;
}
}