update v1.0.4

This commit is contained in:
sujitprasad
2016-01-04 18:05:45 +05:30
parent 372485336b
commit 4864e5a3f1
529 changed files with 20956 additions and 8178 deletions

View File

@@ -1,2 +1,4 @@
vendor
composer.lock
/vendor
/composer.lock
/composer.phar
/.idea

View File

@@ -1,3 +1,4 @@
sudo: false
language: php
php:
- 5.6
@@ -6,7 +7,3 @@ php:
- 5.3
- 5.2
- hhvm
notifications:
hipchat:
rooms:
secure: CP1Pqa5TRwHtft3UQRZpnnw/mRCAVtXAn5S/Am45uk4fpGGFLf3F/mHKOgjDeALB/aVyJQvHV/Lr2KrgY7FWOjOdzXVVwLDtGoXXimvqxGEjvSFQMiJGKiwm7Thw41EqwHOZUxIKLtJBByP36bqvx4zXxUeNbCTc4T2f92eiZps=

View File

@@ -1,6 +1,24 @@
Changelog
=========
2.6.0 (23 Dec 2015)
-----
### Enhancements
* Add support for PHP 7's Throwable
| [Chris Stone](https://github.com/cmstone)
| [#106](https://github.com/bugsnag/bugsnag-php/pull/106)
* Fix errors which arise from from error payloads not encoded using UTF-8
| [GaetanNaulin](https://github.com/GaetanNaulin)
| [#104](https://github.com/bugsnag/bugsnag-php/pull/104)
| [#105](https://github.com/bugsnag/bugsnag-php/pull/105)
2.5.6
-----
- Added a debug flag to help diagnose notification problems
2.5.5
-----
- Ensure no unnecessary code is executed when errors should be skipped

View File

@@ -2,7 +2,7 @@ Contributing
============
- [Fork](https://help.github.com/articles/fork-a-repo) the [notifier on github](https://github.com/bugsnag/bugsnag-laravel)
- Build and test your changes
- Build and test your changes. Run the tests using [phpunit](https://phpunit.de) (vendored to `vendor/bin/phpunit`)
- Commit and push until you are happy with your contribution
- [Make a pull request](https://help.github.com/articles/using-pull-requests)
- Thanks!
@@ -22,15 +22,27 @@ Releasing
=========
1. Commit all outstanding changes
1. Bump the version in `src/Bugsnag/Configuration.php`.
2. Update the CHANGELOG.md, and README if appropriate.
3. Build a new phar package
2. Bump the version in `src/Bugsnag/Configuration.php`.
3. Update the CHANGELOG.md, and README if appropriate.
4. Build a new phar package
* NB: You may need to set `phar.readonly = Off` in /usr/local/etc/php/5.4/php.ini
* If not located in /usr/local/etc, check /private/etc/php.ini
* If not in /private/etc/php.ini:
```
sudo cp /private/etc/php.ini.default /private/etc/php.ini
```
* Then:
```
composer install
php pharbuilder.php
```
4. Commit, tag push
git commit -am v1.x.x
git tag v1.x.x
git push origin master v1.x.x
```
git commit -am v2.x.x
git tag v2.x.x
git push origin master && git push --tags
```

View File

@@ -1,4 +1,4 @@
Bugsnag Notifier for PHP
Bugsnag Notifier for PHP <img src="https://travis-ci.org/bugsnag/bugsnag-php.svg?branch=master" alt="build status" class="build-status">
========================
The Bugsnag Notifier for PHP gives you instant notification of errors and
@@ -161,14 +161,12 @@ you can set the `releaseStage` that is reported to Bugsnag.
$bugsnag->setReleaseStage('development');
```
By default this is set to be "production".
By default this is set to "production".
> Note: If you would like errors from stages other than production to be sent
to Bugsnag, you'll also have to call `setNotifyReleaseStages`.
###setNotifyReleaseStages
By default, we will notify Bugsnag of errors that happen in any
By default, we will notify Bugsnag of errors that happen in *any*
`releaseStage` If you would like to change which release stages notify
Bugsnag of errors you can call `setNotifyReleaseStages`:

Binary file not shown.

View File

@@ -3,13 +3,14 @@
<http://getcomposer.org/doc/01-basic-usage.md>
- Install bugsnag using composer
```shell
composer install
```
- Add your API key to the example script
- Run the example script
```shell
php index.php
```
```

View File

@@ -2,7 +2,7 @@
require_once "../../build/bugsnag.phar";
$bugsnag = new Bugsnag_Client("066f5ad3590596f9aa8d601ea89af845");
$bugsnag = new Bugsnag_Client("YOUR-API-KEY-HERE");
$bugsnag->notifyError("Broken", "Something broke", array("tab" => array("paying" => true, "object" => (object)array("key" => "value"), "null" => NULL, "string" => "test", "int" => 4)));
?>

View File

@@ -3,12 +3,14 @@
class Bugsnag_Client
{
private $config;
/** @var Bugsnag_Notification|null */
private $notification;
/**
* Initialize Bugsnag
*
* @param String $apiKey your Bugsnag API key
* @throws Exception
*/
public function __construct($apiKey)
{
@@ -33,6 +35,7 @@ class Bugsnag_Client
* Set your release stage, eg "production" or "development"
*
* @param String $releaseStage the app's current release stage
* @return $this
*/
public function setReleaseStage($releaseStage)
{
@@ -45,6 +48,7 @@ class Bugsnag_Client
* Set your app's semantic version, eg "1.2.3"
*
* @param String $appVersion the app's version
* @return $this
*/
public function setAppVersion($appVersion)
{
@@ -53,10 +57,11 @@ class Bugsnag_Client
return $this;
}
/**
/**
* Set the host name
*
* @param String $hostname the host name
* @return $this
*/
public function setHostname($hostname)
{
@@ -70,6 +75,7 @@ class Bugsnag_Client
* eg array("production", "development")
*
* @param Array $notifyReleaseStages array of release stages to notify for
* @return $this
*/
public function setNotifyReleaseStages(array $notifyReleaseStages)
{
@@ -82,6 +88,7 @@ class Bugsnag_Client
* Set which Bugsnag endpoint to send errors to.
*
* @param String $endpoint endpoint URL
* @return $this
*/
public function setEndpoint($endpoint)
{
@@ -90,11 +97,25 @@ class Bugsnag_Client
return $this;
}
/**
* Enable debug mode to help diagnose problems.
*
* @param Boolean $debug whether to enable debug mode
* @return $this
*/
public function setDebug($debug)
{
$this->config->debug = $debug;
return $this;
}
/**
* Set whether or not to use SSL when notifying bugsnag
*
* @param Boolean $useSSL whether to use SSL
* @deprecated you can now pass full URLs to setEndpoint
* @return $this
*/
public function setUseSSL($useSSL)
{
@@ -107,6 +128,7 @@ class Bugsnag_Client
* Set the desired timeout for cURL connection when notifying bugsnag
*
* @param Integer $timeout the desired timeout in seconds
* @return $this
*/
public function setTimeout($timeout)
{
@@ -121,6 +143,7 @@ class Bugsnag_Client
* stacktrace lines.
*
* @param String $projectRoot the root path for your application
* @return $this
*/
public function setProjectRoot($projectRoot)
{
@@ -135,6 +158,7 @@ class Bugsnag_Client
* for grouping and reduces the noise in stack traces.
*
* @param String $stripPath the path to strip from filenames
* @return $this
*/
public function setStripPath($stripPath)
{
@@ -148,6 +172,7 @@ class Bugsnag_Client
* that are part of your application.
*
* @param String $projectRootRegex regex matching paths belong to your project
* @return $this
*/
public function setProjectRootRegex($projectRootRegex)
{
@@ -161,6 +186,7 @@ class Bugsnag_Client
* to Bugsnag. Eg. array("password", "credit_card")
*
* @param Array $filters an array of metaData filters
* @return $this
*/
public function setFilters(array $filters)
{
@@ -178,6 +204,7 @@ class Bugsnag_Client
* 'name' => 'Bob Hoskins',
* 'email' => 'bob@hoskins.com'
* )
* @return $this
*/
public function setUser(array $user)
{
@@ -188,6 +215,8 @@ class Bugsnag_Client
/**
* @deprecated deprecated since version 2.1
* @param $userId
* @return $this
*/
public function setUserId($userId)
{
@@ -204,6 +233,7 @@ class Bugsnag_Client
* Set a context representing the current type of request, or location in code.
*
* @param String $context the current context
* @return $this
*/
public function setContext($context)
{
@@ -218,6 +248,7 @@ class Bugsnag_Client
* eg "laravel", or executing through delayed worker code, eg "resque".
*
* @param String $type the current type
* @return $this
*/
public function setType($type)
{
@@ -237,6 +268,7 @@ class Bugsnag_Client
* "email" => "james@example.com"
* )
* )
* @return $this
*/
public function setMetaData(array $metaData)
{
@@ -255,6 +287,7 @@ class Bugsnag_Client
* 'user' => "username"
* 'password' => "password123"
* )
* @return $this
*/
public function setProxySettings(array $proxySettings)
{
@@ -270,6 +303,7 @@ class Bugsnag_Client
* array(
* CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4
* )
* @return $this
*/
public function setCurlOptions(array $curlOptions)
{
@@ -292,8 +326,9 @@ class Bugsnag_Client
* ));
* }
* $bugsnag->setBeforeNotifyFunction("before_bugsnag_notify");
*
*/
* @param callable $beforeNotifyFunction
* @return $this
*/
public function setBeforeNotifyFunction($beforeNotifyFunction)
{
$this->config->beforeNotifyFunction = $beforeNotifyFunction;
@@ -308,6 +343,7 @@ class Bugsnag_Client
*
* @param Integer $errorReportingLevel the error reporting level integer
* exactly as you would pass to PHP's error_reporting
* @return $this
*/
public function setErrorReportingLevel($errorReportingLevel)
{
@@ -321,6 +357,7 @@ class Bugsnag_Client
* exceptions and errors.
*
* @param Boolean $autoNotify whether to auto notify or not
* @return $this
*/
public function setAutoNotify($autoNotify)
{
@@ -334,6 +371,7 @@ class Bugsnag_Client
* each request.
*
* @param Boolean $batchSending whether to batch together errors
* @return $this
*/
public function setBatchSending($batchSending)
{
@@ -347,6 +385,7 @@ class Bugsnag_Client
* set by other notifier libraries.
*
* @param Array $notifier an array of name, version, url.
* @return $this
*/
public function setNotifier($notifier)
{
@@ -359,6 +398,7 @@ class Bugsnag_Client
* Sets whether Bugsnag should send $_ENV with each error.
*
* @param Boolean $sendEnvironment whether to send the environment
* @return $this
*/
public function setSendEnvironment($sendEnvironment)
{
@@ -367,11 +407,38 @@ class Bugsnag_Client
return $this;
}
/**
* Sets whether Bugsnag should send $_COOKIE with each error.
*
* @param Boolean $sendCookies whether to send the environment
* @return $this
*/
public function setSendCookies($sendCookies)
{
$this->config->sendCookies = $sendCookies;
return $this;
}
/**
* Sets whether Bugsnag should send $_SESSION with each error.
*
* @param Boolean $sendSession whether to send the environment
* @return $this
*/
public function setSendSession($sendSession)
{
$this->config->sendSession = $sendSession;
return $this;
}
/**
* Should we send a small snippet of the code that crashed to help you
* diagnose even faster from within your dashboard.
*
* @param Boolean $setSendCode whether to send code to Bugsnag
* @param Boolean $sendCode whether to send code to Bugsnag
* @return $this
*/
public function setSendCode($sendCode)
{
@@ -381,25 +448,27 @@ class Bugsnag_Client
}
/**
* 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);
}
}
/**
* Notify Bugsnag of a non-fatal/handled error
*
* @param String $errorName the name of the error, a short (1 word) string
* @param String $errorMessage the error message
* @param String $name the name of the error, a short (1 word) string
* @param String $message the error message
* @param Array $metaData optional metaData to send with this error
* @param String $severity optional severity of this error (fatal/error/warning/info)
*/
@@ -412,13 +481,13 @@ class Bugsnag_Client
}
// 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);
}

View File

@@ -18,10 +18,12 @@ class Bugsnag_Configuration
public $proxySettings = array();
public $notifier = array(
'name' => 'Bugsnag PHP (Official)',
'version' => '2.5.5',
'version' => '2.6.0',
'url' => 'https://bugsnag.com',
);
public $sendEnvironment = false;
public $sendCookies = true;
public $sendSession = true;
public $sendCode = true;
public $stripPath;
public $stripPathRegex;
@@ -39,6 +41,8 @@ class Bugsnag_Configuration
public $curlOptions = array();
public $debug = false;
public function __construct()
{
$this->timeout = Bugsnag_Configuration::$DEFAULT_TIMEOUT;
@@ -67,8 +71,6 @@ class Bugsnag_Configuration
} else {
return !(error_reporting() & $code);
}
return false;
}
public function setProjectRoot($projectRoot)

View File

@@ -12,10 +12,12 @@ class Bugsnag_Error
public $payloadVersion = "2";
public $message;
public $severity = "warning";
/** @var Bugsnag_Stacktrace */
public $stacktrace;
public $metaData = array();
public $config;
public $diagnostics;
/** @var Bugsnag_Error|null */
public $previous;
public $groupingHash;
@@ -28,10 +30,10 @@ class Bugsnag_Error
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;
}
@@ -74,7 +76,7 @@ class Bugsnag_Error
return $this;
}
public function setStacktrace($stacktrace)
public function setStacktrace(Bugsnag_Stacktrace $stacktrace)
{
$this->stacktrace = $stacktrace;
@@ -141,7 +143,7 @@ class Bugsnag_Error
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;
@@ -181,13 +183,13 @@ class Bugsnag_Error
'stacktrace' => $this->stacktrace->toArray(),
);
return $exceptionArray;
return $this->cleanupObj($exceptionArray);
}
private function cleanupObj($obj)
{
if (is_null($obj)) {
return;
return null;
}
if (is_array($obj)) {

View File

@@ -5,6 +5,7 @@ class Bugsnag_Notification
private static $CONTENT_TYPE_HEADER = 'Content-type: application/json';
private $config;
/** @var Bugsnag_Error[] */
private $errorQueue = array();
public function __construct(Bugsnag_Configuration $config)
@@ -12,7 +13,7 @@ class Bugsnag_Notification
$this->config = $config;
}
public function addError($error, $passedMetaData = array())
public function addError(Bugsnag_Error $error, $passedMetaData = array())
{
// Check if this error should be sent to Bugsnag
if (!$this->config->shouldNotify()) {
@@ -27,6 +28,16 @@ class Bugsnag_Notification
$error->setMetaData(Bugsnag_Request::getRequestMetaData());
}
// Session Tab
if ($this->config->sendSession && !empty($_SESSION)) {
$error->setMetaData(array('session' => $_SESSION));
}
// Cookies Tab
if ($this->config->sendCookies && !empty($_COOKIE)) {
$error->setMetaData(array('cookies' => $_COOKIE));
}
// Add environment meta-data to error
if ($this->config->sendEnvironment && !empty($_ENV)) {
$error->setMetaData(array("Environment" => $_ENV));
@@ -139,6 +150,11 @@ class Bugsnag_Notification
if ($statusCode > 200) {
error_log('Bugsnag Warning: Couldn\'t notify ('.$responseBody.')');
if($this->config->debug) {
error_log('Bugsnag Debug: Attempted to post to URL - "'.$url.'"');
error_log('Bugsnag Debug: Attempted to post payload - "'.$body.'"');
}
}
if (curl_errno($http)) {

View File

@@ -36,16 +36,6 @@ class Bugsnag_Request
$requestData['request']['headers'] = $headers;
}
// Session Tab
if (!empty($_SESSION)) {
$requestData['session'] = $_SESSION;
}
// Cookies Tab
if (!empty($_COOKIE)) {
$requestData['cookies'] = $_COOKIE;
}
return $requestData;
}
@@ -54,7 +44,7 @@ class Bugsnag_Request
if (self::isRequest() && isset($_SERVER['REQUEST_METHOD']) && isset($_SERVER["REQUEST_URI"])) {
return $_SERVER['REQUEST_METHOD'].' '.strtok($_SERVER["REQUEST_URI"], '?');
} else {
return;
return null;
}
}
@@ -63,7 +53,7 @@ class Bugsnag_Request
if (self::isRequest()) {
return self::getRequestIp();
} else {
return;
return null;
}
}

View File

@@ -2,6 +2,11 @@
abstract class Bugsnag_TestCase extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function getError($name = "Name", $message = "Message")
{
return Bugsnag_Error::fromNamedError($this->config, $this->diagnostics, $name, $message);

View File

@@ -2,6 +2,7 @@
class ClientTest extends PHPUnit_Framework_TestCase
{
/** @var PHPUnit_Framework_MockObject_MockObject|Bugsnag_Client */
protected $client;
protected function setUp()
@@ -77,6 +78,6 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testSetInvalidCurlOptions()
{
$return = $this->client->setCurlOptions("option");
$this->client->setCurlOptions("option");
}
}

View File

@@ -2,6 +2,7 @@
class ConfigurationTest extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
protected function setUp()

View File

@@ -2,7 +2,10 @@
class DiagnosticsTest extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function setUp()
{

View File

@@ -4,8 +4,11 @@ require_once 'Bugsnag_TestCase.php';
class ErrorTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
/** @var Bugsnag_Error */
protected $error;
protected function setUp()
@@ -102,7 +105,7 @@ class ErrorTest extends Bugsnag_TestCase
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();

View File

@@ -4,8 +4,11 @@ require_once 'Bugsnag_TestCase.php';
class NotificationTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject */
protected $notification;
protected function setUp()
@@ -64,6 +67,7 @@ class NotificationTest extends Bugsnag_TestCase
->method('shouldNotify')
->will($this->returnValue(false));
/** @var Bugsnag_Notification $notification */
$notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($config))
@@ -86,6 +90,7 @@ class NotificationTest extends Bugsnag_TestCase
->method('shouldNotify')
->will($this->returnValue(false));
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($config))

View File

@@ -4,7 +4,9 @@ require_once 'Bugsnag_TestCase.php';
class StacktraceTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function setUp()