Skip to content

Commit

Permalink
Improve support for PHP 7
Browse files Browse the repository at this point in the history
Fixes #101
Fixes #102
Merges #106
  • Loading branch information
kattrali committed Dec 23, 2015
2 parents bd078cd + 23ac8cd commit 679ff2f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

2.6.0
-----

### Enhancements

* Add support for PHP 7's Throwable
| [Chris Stone](https://github.com/cmstone)
| [#106](https://github.com/bugsnag/bugsnag-php/pull/106)

2.5.6
-----
- Added a debug flag to help diagnose notification problems
Expand Down
18 changes: 10 additions & 8 deletions src/Bugsnag/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,20 @@ public function setSendCode($sendCode)
}

/**
* Notify Bugsnag of a non-fatal/handled exception
* Notify Bugsnag of a non-fatal/handled throwable
*
* @param Exception $exception the exception to notify Bugsnag about
* @param Throwable $throwable the throwable to notify Bugsnag about
* @param Array $metaData optional metaData to send with this error
* @param String $severity optional severity of this error (fatal/error/warning/info)
*/
public function notifyException(Exception $exception, array $metaData = null, $severity = null)
public function notifyException($throwable, array $metaData = null, $severity = null)
{
$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error->setSeverity($severity);
if (is_subclass_of($throwable, 'Throwable') || is_subclass_of($throwable, 'Exception') || get_class($throwable) == 'Exception') {
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
$error->setSeverity($severity);

$this->notify($error, $metaData);
$this->notify($error, $metaData);
}
}

/**
Expand All @@ -479,13 +481,13 @@ public function notifyError($name, $message, array $metaData = null, $severity =
}

// Exception handler callback, should only be called internally by PHP's set_exception_handler
public function exceptionHandler($exception)
public function exceptionHandler($throwable)
{
if(!$this->config->autoNotify) {
return;
}

$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable);
$error->setSeverity("error");
$this->notify($error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bugsnag/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static function fromPHPError(Bugsnag_Configuration $config, Bugsnag_Diagn
return $error;
}

public static function fromPHPException(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, Exception $exception)
public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $throwable)
{
$error = new Bugsnag_Error($config, $diagnostics);
$error->setPHPException($exception);
$error->setPHPException($throwable);

return $error;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public function setMetaData($metaData)
public function setPrevious($exception)
{
if ($exception) {
$this->previous = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$this->previous = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/Bugsnag/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testPreviousException()
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$exception = new Exception("secondly", 65533, new Exception("firstly"));

$error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception);
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);

$errorArray = $error->toArray();

Expand Down

0 comments on commit 679ff2f

Please sign in to comment.