Skip to content

Commit

Permalink
add overridable accessors for submitted data
Browse files Browse the repository at this point in the history
  • Loading branch information
rich committed Jan 24, 2010
1 parent c3f8af0 commit 057ca31
Showing 1 changed file with 100 additions and 38 deletions.
138 changes: 100 additions & 38 deletions Services/Hoptoad.php
Expand Up @@ -34,12 +34,12 @@ class Services_Hoptoad
const NOTIFIER_URL = 'http://github.com/rich/php-hoptoad-notifier'; const NOTIFIER_URL = 'http://github.com/rich/php-hoptoad-notifier';
const NOTIFIER_API_VERSION = '2.0'; const NOTIFIER_API_VERSION = '2.0';


protected $error_class; protected $error_class;
protected $message; protected $message;
protected $file; protected $file;
protected $line; protected $line;
protected $trace; protected $trace;

/** /**
* Report E_STRICT * Report E_STRICT
* *
Expand Down Expand Up @@ -113,15 +113,15 @@ public static function exceptionHandler($exception)
$hoptoad->notify(); $hoptoad->notify();
} }


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

/** /**
* Pass the error and environment data on to Hoptoad * Pass the error and environment data on to Hoptoad
* *
Expand All @@ -134,7 +134,7 @@ function __construct($error_class, $message, $file, $line, $trace, $component=NU
* @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()
{ {
Expand Down Expand Up @@ -179,16 +179,16 @@ function buildXmlNotice()


$request = $doc->addChild('request'); $request = $doc->addChild('request');
$request->addChild('url', $this->request_uri()); $request->addChild('url', $this->request_uri());
$request->addChild('component', $this->component); $request->addChild('component', $this->component());
$request->addChild('action', $this->action());


if (isset($_REQUEST)) $this->addXmlVars($request, 'params', $_REQUEST); if (isset($_REQUEST)) $this->addXmlVars($request, 'params', $this->params());
if (isset($_SESSION)) $this->addXmlVars($request, 'session', $_SESSION); if (isset($_SESSION)) $this->addXmlVars($request, 'session', $this->session());
if (isset($_SERVER)) $this->addXmlVars($request, 'cgi-data', $_SERVER); if (isset($_SERVER)) $this->addXmlVars($request, 'cgi-data', $this->cgi_data());
if (isset($_ENV)) $this->addXmlVars($request, 'cgi-data', $_ENV);


$env = $doc->addChild('server-environment'); $env = $doc->addChild('server-environment');
$env->addChild('project-root', $_SERVER['DOCUMENT_ROOT']); $env->addChild('project-root', $this->project_root());
$env->addChild('environment-name', self::$environment); $env->addChild('environment-name', $this->environment());


return $doc->asXML(); return $doc->asXML();
} }
Expand Down Expand Up @@ -232,22 +232,84 @@ function addXmlBacktrace($parent)
} }


/** /**
* get the request uri * params
* @return string * @return array
* @author Scott Woods * @author Scott Woods
**/
function params() {
return $_REQUEST;
}

/**
* session
* @return array
* @author Scott Woods
**/ **/
function request_uri() { function session() {
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { return $_SESSION;
$protocol = 'https'; }
} else {
$protocol = 'http'; /**
} * cgi_data
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; * @return array
$path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; * @author Scott Woods
$query_string = isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''; **/
return "{$protocol}://{$host}{$path}{$query_string}"; function cgi_data() {
} if (isset($_ENV) && !empty($_ENV)) {

return array_merge($_SERVER, $_ENV);
}
return $_SERVER;
}

/**
* component
* @return mixed
* @author Scott Woods
**/
function component() {
return $this->component;
}

/**
* action
* @return mixed
* @author Scott Woods
**/
function action() {
return '';
}

/**
* project_root
* @return string
* @author Scott Woods
**/
function project_root() {
if (isset($_SERVER['DOCUMENT_ROOT'])) {
return $_SERVER['DOCUMENT_ROOT'];
} else {
return dirname(__FILE__);
}
}


/**
* get the request uri
* @return string
* @author Scott Woods
**/
function request_uri() {
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) {
$protocol = 'https';
} else {
$protocol = 'http';
}
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$query_string = isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '';
return "{$protocol}://{$host}{$path}{$query_string}";
}

/** /**
* @param mixed $code The HTTP status code from Hoptoad. * @param mixed $code The HTTP status code from Hoptoad.
* *
Expand All @@ -273,7 +335,7 @@ protected function handleErrorResponse($code)


throw new RuntimeException($msg, $code); throw new RuntimeException($msg, $code);
} }

/** /**
* Send the request to Hoptoad using PEAR * Send the request to Hoptoad using PEAR
* @return integer * @return integer
Expand All @@ -283,7 +345,7 @@ public function pearRequest($url, $headers, $body)
{ {
if (!class_exists('HTTP_Request2')) require_once('HTTP/Request2.php'); if (!class_exists('HTTP_Request2')) require_once('HTTP/Request2.php');
if (!class_exists('HTTP_Request2_Adapter_Socket')) require_once 'HTTP/Request2/Adapter/Socket.php'; if (!class_exists('HTTP_Request2_Adapter_Socket')) require_once 'HTTP/Request2/Adapter/Socket.php';

$adapter = new HTTP_Request2_Adapter_Socket; $adapter = new HTTP_Request2_Adapter_Socket;
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST); $req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
$req->setAdapter($adapter); $req->setAdapter($adapter);
Expand Down

0 comments on commit 057ca31

Please sign in to comment.