Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:getsentry/raven-php

  • Loading branch information...
commit 8b06a2210ff07d913d20f5a57cc3d4da3d4eee16 2 parents a84384d + a78c451
David Cramer dcramer authored
24 lib/Raven/Client.php
View
@@ -132,7 +132,7 @@ public function captureMessage($message, $params=array(), $level=self::INFO,
/**
* Log an exception to sentry
*/
- public function captureException($exception)
+ public function captureException($exception, $culprit=null, $logger=null)
{
$exc_message = $exception->getMessage();
if (empty($exc_message)) {
@@ -140,15 +140,24 @@ public function captureException($exception)
}
$data = array(
- 'message' => $exc_message,
- 'sentry.interfaces.Exception' => array(
- 'value' => '',
+ 'message' => $exc_message
+ );
+
+ $data['sentry.interfaces.Exception'] = array(
+ 'value' => $exc_message,
'type' => $exception->getCode(),
'module' => $exception->getFile() .':'. $exception->getLine(),
- )
);
- /**
+ if ($culprit){
+ $data["culprit"] = $culprit;
+ }
+
+ if ($logger){
+ $data["logger"] = $logger;
+ }
+
+ /**'sentry.interfaces.Exception'
* Exception::getTrace doesn't store the point at where the exception
* was thrown, so we have to stuff it in ourselves. Ugh.
*/
@@ -158,7 +167,6 @@ public function captureException($exception)
'line' => $exception->getLine(),
);
array_unshift($trace, $frame_where_exception_thrown);
-
return $this->capture($data, $trace);
}
@@ -246,7 +254,7 @@ public function send($data)
private function send_remote($url, $data, $headers=array())
{
$parts = parse_url($url);
- $parts['netloc'] = $parts['host'].($parts['port'] ? ':'.$parts['port'] : null);
+ $parts['netloc'] = $parts['host'].(isset($parts['port']) ? ':'.$parts['port'] : null);
if ($parts['scheme'] === 'udp')
return $this->send_udp($parts['netloc'], $data, $headers['X-Sentry-Auth']);
39 lib/Raven/ErrorHandler.php
View
@@ -14,8 +14,8 @@
*
* $client = new Raven_Client('http://public:secret/example.com/1');
* $error_handler = new Raven_ErrorHandler($client);
- * set_error_handler(array($error_handler, 'handleError');
- * set_exception_handler(array($error_handler, 'handleException'));
+ * $error_handler->registerExceptionHandler();
+ * $error_handler->registerErrorHandler();
*
* @package raven
*/
@@ -26,13 +26,40 @@ function __construct($client) {
$this->client = $client;
}
- function handleException($e) {
- $this->client->captureException($e);
+ function handleException($e, $isError = false) {
+ $e->event_id = $this->client->getIdent($this->client->captureException($e));
+
+ if (!$isError && $this->call_existing_exception_handler && $this->old_exception_handler) {
+ call_user_func($this->old_exception_handler, $e);
+ }
}
function handleError($code, $message, $file='', $line=0, $context=array()) {
+
$e = new ErrorException($message, 0, $code, $file, $line);
- $this->handleException($e);
+ $this->handleException($e, $isError = true);
+
+
+ if ($this->call_existing_error_handler && $this->old_error_handler) {
+ call_user_func($this->old_error_handler, $code, $message, $file, $line, $context);
+ }
+ }
+
+ function registerExceptionHandler($call_existing_exception_handler = true)
+ {
+ $this->old_exception_handler = set_exception_handler(array($this, 'handleException'));
+ $this->call_existing_exception_handler = $call_existing_exception_handler;
+ }
+
+ function registerErrorHandler($call_existing_error_handler = true, $error_types = E_ALL)
+ {
+ $this->old_error_handler = set_error_handler(array($this, 'handleError'), $error_types);
+ $this->call_existing_error_handler = $call_existing_error_handler;
}
+
+ private $old_exception_handler = null;
+ private $call_existing_exception_handler = false;
+ private $old_error_handler = null;
+ private $call_existing_error_handler = false;
}
-?>
+?>
30 test/Raven/Tests/ClientTest.php
View
@@ -51,28 +51,34 @@ public function testParseDsnPort()
$this->assertEquals($result['secret_key'], 'secret');
}
- /**
- * @expectedException InvalidArgumentException
- */
public function testParseDsnInvalidScheme()
{
- $result = Raven_Client::parseDsn('gopher://public:secret@/1');
+ try {
+ $result = Raven_Client::parseDsn('gopher://public:secret@/1');
+ $this->fail();
+ } catch (Exception $e) {
+ return;
+ }
}
- /**
- * @expectedException InvalidArgumentException
- */
public function testParseDsnMissingNetloc()
{
- $result = Raven_Client::parseDsn('http://public:secret@/1');
+ try {
+ $result = Raven_Client::parseDsn('http://public:secret@/1');
+ $this->fail();
+ } catch (Exception $e) {
+ return;
+ }
}
- /**
- * @expectedException InvalidArgumentException
- */
public function testParseDsnMissingProject()
{
- $result = Raven_Client::parseDsn('http://public:secret@example.com');
+ try {
+ $result = Raven_Client::parseDsn('http://public:secret@example.com');
+ $this->fail();
+ } catch (Exception $e) {
+ return;
+ }
}
/**
4 test/Raven/Tests/ErrorHandlerTest.php
View
@@ -13,7 +13,7 @@ class Raven_Tests_ErrorHandlerTest extends PHPUnit_Framework_TestCase
{
public function testErrorsAreLoggedAsExceptions()
{
- $client = $this->getMock('Client', array('captureException'));
+ $client = $this->getMock('Client', array('captureException', 'getIdent'));
$client->expects($this->once())
->method('captureException')
->with($this->isInstanceOf('ErrorException'));
@@ -24,7 +24,7 @@ public function testErrorsAreLoggedAsExceptions()
public function testExceptionsAreLogged()
{
- $client = $this->getMock('Client', array('captureException'));
+ $client = $this->getMock('Client', array('captureException', 'getIdent'));
$client->expects($this->once())
->method('captureException')
->with($this->isInstanceOf('ErrorException'));
Please sign in to comment.
Something went wrong with that request. Please try again.