Skip to content

Commit

Permalink
eliminate more static functions to make subclassing easier
Browse files Browse the repository at this point in the history
  • Loading branch information
rich committed Jan 24, 2010
1 parent f7b822f commit c263925
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions Services/Hoptoad.php
Expand Up @@ -72,14 +72,15 @@ class Services_Hoptoad
* @return void * @return void
* @author Rich Cavanaugh * @author Rich Cavanaugh
*/ */
public static function installHandlers($api_key=NULL, $environment=NULL, $client=NULL) public static function installHandlers($api_key=NULL, $environment=NULL, $client=NULL, $class='Services_Hoptoad')
{ {
if (isset($api_key)) self::$apiKey = $api_key; if (isset($api_key)) self::$apiKey = $api_key;
if (isset($environment)) self::$environment = $environment; if (isset($environment)) self::$environment = $environment;
if (isset($client)) self::$client = $client; if (isset($client)) self::$client = $client;


set_error_handler(array("Services_Hoptoad", "errorHandler")); $hoptoad = new $class;
set_exception_handler(array("Services_Hoptoad", "exceptionHandler")); set_error_handler(array($hoptoad, "errorHandler"));
set_exception_handler(array($hoptoad, "exceptionHandler"));
} }


/** /**
Expand All @@ -92,12 +93,11 @@ public static function installHandlers($api_key=NULL, $environment=NULL, $client
* @return void * @return void
* @author Rich Cavanaugh * @author Rich Cavanaugh
*/ */
public static function errorHandler($code, $message, $file, $line) public function errorHandler($code, $message, $file, $line)
{ {
if ($code == E_STRICT && self::$reportESTRICT === false) return; if ($code == E_STRICT && self::$reportESTRICT === false) return;


$hoptoad = new self($code, $message, $file, $line, debug_backtrace()); $this->notify($code, $message, $file, $line, debug_backtrace());
$hoptoad->notify();
} }


/** /**
Expand All @@ -107,37 +107,33 @@ public static function errorHandler($code, $message, $file, $line)
* @return void * @return void
* @author Rich Cavanaugh * @author Rich Cavanaugh
*/ */
public static function exceptionHandler($exception) public function exceptionHandler($exception)
{ {
$hoptoad = new self(get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTrace()); $this->notify(get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTrace());
$hoptoad->notify();
}

function __construct($error_class, $message, $file, $line, $trace, $component=NULL) {
$this->error_class = $error_class;
$this->message = $message;
$this->file = $file;
$this->line = $line;
$this->trace = $trace;
$this->component = $component;
} }


/** /**
* Pass the error and environment data on to Hoptoad * Pass the error and environment data on to Hoptoad
* *
* @param string $api_key * @param mixed $error_class
* @param string $message * @param string $message
* @param string $file * @param string $file
* @param string $line * @param string $line
* @param array $trace * @param array $trace
* @param mixed $error_class
* @param string $environment * @param string $environment
* *
* @author Rich Cavanaugh * @author Rich Cavanaugh
* @todo Handle response (e.g. errors) * @todo Handle response (e.g. errors)
*/ */
function notify() function notify($error_class, $message, $file, $line, $trace, $component=NULL)
{ {
$this->error_class = $error_class;
$this->message = $message;
$this->file = $file;
$this->line = $line;
$this->trace = $trace;
$this->component = $component;

$url = "http://hoptoadapp.com/notifier_api/v2/notices"; $url = "http://hoptoadapp.com/notifier_api/v2/notices";
$headers = array( $headers = array(
'Accept' => 'text/xml, application/xml', 'Accept' => 'text/xml, application/xml',
Expand Down

0 comments on commit c263925

Please sign in to comment.