diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d3895f..03092093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Bugsnag/Client.php b/src/Bugsnag/Client.php index a9fb71da..5b49c97c 100644 --- a/src/Bugsnag/Client.php +++ b/src/Bugsnag/Client.php @@ -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); + } } /** @@ -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); } diff --git a/src/Bugsnag/Error.php b/src/Bugsnag/Error.php index dedd9aa5..06c0c8da 100644 --- a/src/Bugsnag/Error.php +++ b/src/Bugsnag/Error.php @@ -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; } @@ -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; diff --git a/tests/Bugsnag/ErrorTest.php b/tests/Bugsnag/ErrorTest.php index 26ff1160..772bd23c 100644 --- a/tests/Bugsnag/ErrorTest.php +++ b/tests/Bugsnag/ErrorTest.php @@ -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();