Permalink
Browse files

Rename Hoptoad to Airbrake http://robots.thoughtbot.com/post/76654117…

  • Loading branch information...
aaronpk committed Jul 17, 2011
1 parent 33bbe21 commit 0dd5903e34328d6ea9e2545b9934e88388a64f65
View
@@ -1,6 +1,6 @@
# Introduction
-This is a simple [Hoptoad](http://hoptoadapp.com) notifier for PHP. It's been used in a few production sites now with success. It's not quite as fully featured as the official Ruby notifier but it works well.
+This is a simple [Airbrake](http://airbrakeapp.com), (formerly Hoptoad) notifier for PHP. It's been used in a few production sites now with success. It's not quite as fully featured as the official Ruby notifier but it works well.
# Thanks
@@ -1,21 +1,21 @@
<?php
/**
- * Services_Hoptoad
+ * Services_Airbrake
*
* @category error
- * @package Services_Hoptoad
+ * @package Services_Airbrake
* @author Rich Cavanaugh <no@email>
* @author Till Klampaeckel <till@php.net>
* @author Aaron Parecki <aaron@parecki.com>
* @license
* @version GIT: $Id$
- * @link http://github.com/geoloqi/php-hoptoad-notifier
+ * @link http://github.com/geoloqi/php-airbrake-notifier
*/
-class Services_Hoptoad
+class Services_Airbrake
{
- const NOTIFIER_NAME = 'php-hoptoad-notifier';
- const NOTIFIER_VERSION = '0.2.1';
- const NOTIFIER_URL = 'http://github.com/geoloqi/php-hoptoad-notifier';
+ const NOTIFIER_NAME = 'php-airbrake-notifier';
+ const NOTIFIER_VERSION = '0.2.2';
+ const NOTIFIER_URL = 'http://github.com/geoloqi/php-airbrake-notifier';
const NOTIFIER_API_VERSION = '2.0';
protected $error_class;
@@ -38,7 +38,7 @@ class Services_Hoptoad
*/
protected $timeout;
- public $client; // pear, curl or zend
+ public $client; // pear, curl, zend or beanstalk
/**
* @var mixed $apiKey
@@ -52,15 +52,15 @@ class Services_Hoptoad
/**
* Initialize the chosen notifier and install the error
- * and exception handlers that connect to Hoptoad
+ * and exception handlers that connect to Airbrake
*
* @return void
* @author Rich Cavanaugh
*/
- public static function installHandlers($apiKey=NULL, $environment=NULL, $client=NULL, $class='Services_Hoptoad')
+ public static function installHandlers($apiKey=NULL, $environment=NULL, $client=NULL, $class='Services_Airbrake')
{
- $hoptoad = new $class($apiKey, $environment, $client);
- $hoptoad->installNotifierHandlers();
+ $airbrake = new $class($apiKey, $environment, $client);
+ $airbrake->installNotifierHandlers();
}
/**
@@ -145,11 +145,12 @@ public function exceptionHandler($exception)
public function fatalErrorHandler()
{
$error = error_get_last();
- $this->notify($error['type'], $error['message'], $error['file'], $error['line'], debug_backtrace());
+ if($error)
+ $this->notify($error['type'], $error['message'], $error['file'], $error['line'], debug_backtrace());
}
/**
- * Set the values to be used for the next notice sent to Hoptoad
+ * Set the values to be used for the next notice sent to Airbrake
* @return void
* @author Rich Cavanaugh
**/
@@ -164,7 +165,7 @@ public function setParamsForNotify($error_class, $message, $file, $line, $trace,
}
/**
- * Pass the error and environment data on to Hoptoad
+ * Pass the error and environment data on to Airbrake
*
* @param mixed $error_class
* @param string $message
@@ -180,7 +181,7 @@ function notify($error_class, $message, $file, $line, $trace, $component=NULL)
{
$this->setParamsForNotify($error_class, $message, $file, $line, $trace, $component);
- $url = "http://hoptoadapp.com/notifier_api/v2/notices";
+ $url = "http://airbrakeapp.com/notifier_api/v2/notices";
$headers = array(
'Accept' => 'text/xml, application/xml',
'Content-Type' => 'text/xml'
@@ -199,7 +200,7 @@ function notify($error_class, $message, $file, $line, $trace, $component=NULL)
/**
* Build up the XML to post according to the documentation at:
- * http://help.hoptoadapp.com/faqs/api-2/notifier-api-v2
+ * http://help.airbrakeapp.com/faqs/api-2/notifier-api-v2
* @return string
* @author Rich Cavanaugh
**/
@@ -240,7 +241,7 @@ function buildXmlNotice()
}
/**
- * Add a Hoptoad var block to the XML
+ * Add a Airbrake var block to the XML
* @return void
* @author Rich Cavanaugh
**/
@@ -256,7 +257,7 @@ function addXmlVars($parent, $key, $source)
}
/**
- * Add a Hoptoad backtrace to the XML
+ * Add a Airbrake backtrace to the XML
* @return void
* @author Rich Cavanaugh
**/
@@ -268,7 +269,7 @@ function addXmlBacktrace($parent)
$line_node->addAttribute('number', $this->line);
foreach ($this->trace as $entry) {
- if (isset($entry['class']) && $entry['class'] == 'Services_Hoptoad') continue;
+ if (isset($entry['class']) && $entry['class'] == 'Services_Airbrake') continue;
$line_node = $backtrace->addChild('line');
$line_node->addAttribute('file', $entry['file']);
@@ -380,10 +381,10 @@ function request_uri() {
}
/**
- * @param mixed $code The HTTP status code from Hoptoad.
+ * @param mixed $code The HTTP status code from Airbrake.
*
* @return void
- * @throws RuntimeException Error message from hoptoad, translated to a RuntimeException.
+ * @throws RuntimeException Error message from airbrake, translated to a RuntimeException.
*/
protected function handleErrorResponse($code)
{
@@ -395,18 +396,18 @@ protected function handleErrorResponse($code)
$msg = 'The submitted notice was invalid - check the notice xml against the schema.';
break;
case '500':
- $msg = 'Unexpected errors - submit a bug report at http://help.hoptoadapp.com.';
+ $msg = 'Unexpected errors - submit a bug report at http://help.airbrakeapp.com.';
break;
default:
- $msg = 'Unknown error code from Hoptoad\'s API: ' . $code;
+ $msg = 'Unknown error code from Airbrake\'s API: ' . $code;
break;
}
throw new RuntimeException($msg, $code);
}
/**
- * Send the request to Hoptoad using PEAR
+ * Send the request to Airbrake using PEAR
* @return integer
* @author Rich Cavanaugh
**/
@@ -424,7 +425,7 @@ public function pearRequest($url, $headers, $body)
}
/**
- * Send the request to Hoptoad using Curl
+ * Send the request to Airbrake using Curl
* @return integer
* @author Rich Cavanaugh
**/
@@ -451,7 +452,7 @@ public function curlRequest($url, $headers, $body)
/**
* Put the error on a beanstalk queue so a separate process can
- * send it off to Hoptoad via HTTP. Requires the pheanstalk client.
+ * send it off to Airbrake via HTTP. Requires the pheanstalk client.
* Config:
* $BEANSTALK_SERVERS[] = array(
* 'host' => 'example.com',
@@ -467,12 +468,12 @@ public function beanstalkRequest($url, $headers, $body)
$k = array_rand($BEANSTALK_SERVERS);
$pheanstalk = new Pheanstalk($BEANSTALK_SERVERS[$k]['host'], $BEANSTALK_SERVERS[$k]['port']);
- $pheanstalk->useTube('hoptoad');
+ $pheanstalk->useTube('airbrake');
$pheanstalk->put(json_encode(array('url'=>$url, 'headers'=>$headers, 'body'=>$body)));
}
/**
- * Send the request to Hoptoad using Zend
+ * Send the request to Airbrake using Zend
* @return integer
* @author Rich Cavanaugh
**/
@@ -1,5 +1,5 @@
<?php
-class Services_Hoptoad_CodeIgniter extends Services_Hoptoad {
+class Services_Airbrake_CodeIgniter extends Services_Airbrake {
var $ci;
function setup() {
View
@@ -1,19 +1,19 @@
<?php
-require_once('php-hoptoad-notifier/Services/Hoptoad.php');
+require_once('php-airbrake-notifier/Services/Airbrake.php');
require_once('pheanstalk/pheanstalk_init.php');
-$hoptoad = new Services_Hoptoad(HOPTOAD_API_KEY);
+$airbrake = new Services_Airbrake(HOPTOAD_API_KEY);
$k = array_rand($BEANSTALK_SERVERS);
$pheanstalk = new Pheanstalk($BEANSTALK_SERVERS[$k]['host'], $BEANSTALK_SERVERS[$k]['port']);
-$pheanstalk->watch('hoptoad')->ignore('default');
+$pheanstalk->watch('airbrake')->ignore('default');
while($job = $pheanstalk->reserve())
{
$data = json_decode($job->getData());
echo date('Y-m-d H:i:s') . ' Processing Error: ' . $data->url . "\n";
- $hoptoad->curlRequest($data->url, $data->headers, $data->body);
+ $airbrake->curlRequest($data->url, $data->headers, $data->body);
$pheanstalk->delete($job);
}
View
@@ -1,41 +1,41 @@
<?php
-// register Services_Hoptoad for php errors and raised exceptions
-require_once 'Services/Hoptoad.php';
-Services_Hoptoad::installHandlers("YOUR_HOPTOAD_API_KEY");
+// register Services_Airbrake for php errors and raised exceptions
+require_once 'Services/Airbrake.php';
+Services_Airbrake::installHandlers("YOUR_AIRBRAKE_API_KEY");
?>
<?php
-// register Services_Hoptoad for php errors and raised exceptions
+// register Services_Airbrake for php errors and raised exceptions
// when used in your staging environment
-require_once 'Services/Hoptoad.php';
-Services_Hoptoad::installHandlers("YOUR_HOPTOAD_API_KEY", 'staging');
+require_once 'Services/Airbrake.php';
+Services_Airbrake::installHandlers("YOUR_AIRBRAKE_API_KEY", 'staging');
?>
<?php
-// register Services_Hoptoad for php errors and raised exceptions
+// register Services_Airbrake for php errors and raised exceptions
// when used in production and using the Curl transport
-require_once 'Services/Hoptoad.php';
-Services_Hoptoad::installHandlers("YOUR_HOPTOAD_API_KEY", 'production', 'curl');
+require_once 'Services/Airbrake.php';
+Services_Airbrake::installHandlers("YOUR_AIRBRAKE_API_KEY", 'production', 'curl');
?>
<?php
// standalone
-require_once 'Services/Hoptoad.php';
+require_once 'Services/Airbrake.php';
-Services_Hoptoad::$apiKey = "YOUR_HOPTOAD_API_KEY";
+Services_Airbrake::$apiKey = "YOUR_AIRBRAKE_API_KEY";
$exception = new Custom_Exception('foobar');
-Services_Hoptoad::handleException($exception);
+Services_Airbrake::handleException($exception);
?>
<?php
// use Zend_Http_Client
-require_once 'Services/Hoptoad.php';
+require_once 'Services/Airbrake.php';
-Services_Hoptoad::$apiKey = "YOUR_HOPTOAD_API_KEY";
-Services_Hoptoad::$client = "zend";
+Services_Airbrake::$apiKey = "YOUR_AIRBRAKE_API_KEY";
+Services_Airbrake::$client = "zend";
$exception = new Custom_Exception('foobar');
-Services_Hoptoad::handleException($exception);
+Services_Airbrake::handleException($exception);
?>
File renamed without changes.
View
@@ -1,7 +1,7 @@
<?php
require_once 'PHPUnit/Framework.php';
-require_once 'Services/Hoptoad.php';
+require_once 'Services/Airbrake.php';
$_SERVER = array(
'HTTP_HOST' => 'localhost',
@@ -26,15 +26,15 @@
$_REQUEST = array_merge($_GET, $_POST);
-class HoptoadTest extends PHPUnit_Framework_TestCase
+class AirbrakeTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
- $this->hoptoad = new Services_Hoptoad('myAPIKey', 'production', 'pear', false, 2);
+ $this->airbrake = new Services_Airbrake('myAPIKey', 'production', 'pear', false, 2);
$trace = array(
array(
- 'class' => 'Hoptoad',
+ 'class' => 'Airbrake',
'file' => 'file.php',
'line' => 23,
'function' => 'foo',
@@ -52,20 +52,20 @@ protected function setUp()
'function' => 'bar',
),
);
- $this->hoptoad->setParamsForNotify('ERROR', 'Something went wrong', 'foo', 23, $trace);
+ $this->airbrake->setParamsForNotify('ERROR', 'Something went wrong', 'foo', 23, $trace);
}
public function testRequestURI()
{
// check protocol support
- $this->assertEquals('http://localhost/example.php', $this->hoptoad->request_uri());
+ $this->assertEquals('http://localhost/example.php', $this->airbrake->request_uri());
$_SERVER['SERVER_PORT'] = 443;
- $this->assertEquals('https://localhost/example.php', $this->hoptoad->request_uri());
+ $this->assertEquals('https://localhost/example.php', $this->airbrake->request_uri());
$_SERVER['SERVER_PORT'] = 80;
// Check query string support.
$_SERVER['QUERY_STRING'] = 'commit=true';
- $this->assertEquals('http://localhost/example.php?commit=true', $this->hoptoad->request_uri());
+ $this->assertEquals('http://localhost/example.php?commit=true', $this->airbrake->request_uri());
$_SERVER['QUERY_STRING'] = '';
}
@@ -82,7 +82,7 @@ public function testXMLBacktrace()
</root>
XML;
$doc = new SimpleXMLElement('<root />');
- $this->hoptoad->addXmlBacktrace($doc);
+ $this->airbrake->addXmlBacktrace($doc);
$this->assertXmlStringEqualsXmlString($expected_xml, $doc->asXML());
}
@@ -99,15 +99,15 @@ public function testXMLParams()
</root>
XML;
$doc = new SimpleXMLElement('<root />');
- $this->hoptoad->addXmlVars($doc, 'params', $_REQUEST);
+ $this->airbrake->addXmlVars($doc, 'params', $_REQUEST);
$this->assertXmlStringEqualsXmlString($expected_xml, $doc->asXML());
}
public function testNotificationBody()
{
- $xmllint = popen('xmllint --noout --schema test/hoptoad_2_0.xsd - 2> /dev/null', 'w');
+ $xmllint = popen('xmllint --noout --schema test/airbrake_2_0.xsd - 2> /dev/null', 'w');
if ($xmllint) {
- fwrite($xmllint, $this->hoptoad->buildXmlNotice());
+ fwrite($xmllint, $this->airbrake->buildXmlNotice());
$status = pclose($xmllint);
$this->assertEquals(0, $status, "XML output did not validate against schema.");
} else {

0 comments on commit 0dd5903

Please sign in to comment.