Handle deprecation notices softer
parent
e64470c987
commit
1753c275ff
|
@ -65,7 +65,6 @@ class Application extends BaseApplication
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorHandler::register();
|
|
||||||
parent::__construct('Composer', Composer::VERSION);
|
parent::__construct('Composer', Composer::VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +88,7 @@ class Application extends BaseApplication
|
||||||
public function doRun(InputInterface $input, OutputInterface $output)
|
public function doRun(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
|
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
|
||||||
|
ErrorHandler::register($this->io);
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 50302) {
|
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>');
|
$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>');
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
namespace Composer\Util;
|
namespace Composer\Util;
|
||||||
|
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert PHP errors into exceptions
|
* Convert PHP errors into exceptions
|
||||||
*
|
*
|
||||||
|
@ -19,6 +21,8 @@ namespace Composer\Util;
|
||||||
*/
|
*/
|
||||||
class ErrorHandler
|
class ErrorHandler
|
||||||
{
|
{
|
||||||
|
private static $io;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error handler
|
* Error handler
|
||||||
*
|
*
|
||||||
|
@ -42,7 +46,22 @@ class ErrorHandler
|
||||||
"\na legitimately suppressed error that you were not supposed to see.";
|
"\na legitimately suppressed error that you were not supposed to see.";
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \ErrorException($message, 0, $level, $file, $line);
|
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))));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,8 +69,9 @@ class ErrorHandler
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
public static function register()
|
public static function register(IOInterface $io = null)
|
||||||
{
|
{
|
||||||
set_error_handler(array(__CLASS__, 'handle'));
|
set_error_handler(array(__CLASS__, 'handle'));
|
||||||
|
self::$io = $io;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue