Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

a few simple comments

  • Loading branch information...
commit 574f079cc3578c7d0cf57856dec113efa4580471 1 parent 3e21705
Rich Cavanaugh rich authored
Showing with 39 additions and 2 deletions.
  1. +39 −2 Hoptoad.php
41 Hoptoad.php
View
@@ -5,12 +5,28 @@
class Hoptoad
{
+ /**
+ * Install the error and exception handlers that connect to Hoptoad
+ *
+ * @return void
+ * @author Rich Cavanaugh
+ */
public static function installHandlers()
{
set_error_handler(array("Hoptoad", "errorHandler"));
set_exception_handler(array("Hoptoad", "exceptionHandler"));
}
+ /**
+ * Handle a php error
+ *
+ * @param string $code
+ * @param string $message
+ * @param string $file
+ * @param string $line
+ * @return void
+ * @author Rich Cavanaugh
+ */
public static function errorHandler($code, $message, $file, $line)
{
if ($code == E_STRICT) return;
@@ -19,6 +35,13 @@ public static function errorHandler($code, $message, $file, $line)
Hoptoad::notifyHoptoad(HOPTOAD_API_KEY, $message, $file, $line, $trace, null);
}
+ /**
+ * Handle a raised exception
+ *
+ * @param string $exception
+ * @return void
+ * @author Rich Cavanaugh
+ */
public static function exceptionHandler($exception)
{
$trace = Hoptoad::tracer($exception->getTrace());
@@ -26,6 +49,12 @@ public static function exceptionHandler($exception)
Hoptoad::notifyHoptoad(HOPTOAD_API_KEY, $exception->getMessage(), $exception->getFile(), $exception->getLine(), $trace, null);
}
+ /**
+ * Pass the error and environment data on to Hoptoad
+ *
+ * @package default
+ * @author Rich Cavanaugh
+ */
public static function notifyHoptoad($api_key, $message, $file, $line, $trace, $error_class=null)
{
$req =& new HTTP_Request("http://hoptoadapp.com/notices/", array("method" => "POST", "timeout" => 2));
@@ -39,13 +68,14 @@ public static function notifyHoptoad($api_key, $message, $file, $line, $trace, $
} else {
$session = array();
}
-
+
+ $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$body = array(
'api_key' => $api_key,
'error_class' => $error_class,
'error_message' => $message,
'backtrace' => $trace,
- 'request' => array("params" => $_REQUEST, "url" => "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
+ 'request' => array("params" => $_REQUEST, "url" => $url),
'session' => $session,
'environment' => $_SERVER
);
@@ -54,6 +84,13 @@ public static function notifyHoptoad($api_key, $message, $file, $line, $trace, $
$req->sendRequest();
}
+ /**
+ * Build a trace that is formatted in the way Hoptoad expects
+ *
+ * @param string $trace
+ * @return void
+ * @author Rich Cavanaugh
+ */
public static function tracer($trace = NULL)
{
$lines = Array();
Please sign in to comment.
Something went wrong with that request. Please try again.