protected function createMockRequest($url = 'http://localhost:3000/', $response_file = 'test_ok.txt') { $errornot = Services_ErrorNot::getInstance(true)->setUrl($url)->setApi('test-key'); $mock_network = createMockRequest($response_file, 'MyMockAdapter'); $errornot->setNetworkAdapter($mock_network); return array($errornot, $mock_network); }
function custom_error_handler_($errno, $errstr, $errfile, $errline, $bt = NULL) { global $custom_error_handler_redirection; if (($errno == E_NOTICE || $errno == E_USER_NOTICE) && ONERROR_REPORT_EVEN_NOTICES == FALSE) { return; } if (($errno & error_reporting()) === 0 && ONERROR_REPORT_EVEN_IGNORED == FALSE) { return; } if ((ONERROR_SHOW | ERRORNOT_ENABLED) == FALSE) { return; } if (function_exists('skycache_no_store')) { skycache_no_store(); } $trace = ''; if (empty($bt)) { $bt = debug_backtrace(); array_shift($bt); } foreach ($bt as $t) { if (!is_array($t) || !isset($t['function'])) { continue; } $trace = $t['function'] . '() -> ' . $trace; } $trace .= '*KABOOM*'; $bt_dump = addcslashes(print_r($bt, TRUE), "\\\r"); $server_dump = addcslashes(print_r($_SERVER, TRUE), "\\\r"); $html = _custom_error_handler_html($errno, $errstr, $errfile, $errline, $trace, $bt_dump, $server_dump); if (ONERROR_SHOW != FALSE) { print $html; } else { if (empty($custom_error_handler_redirection)) { $custom_error_handler_redirection = ONERROR_URI_TEMPORARY; } if (isset($_SERVER['HTTP_HOST']) && preg_match('|^\\w+://.|', $custom_error_handler_redirection) <= 0) { $custom_error_handler_redirection = 'http://' . rawurlencode($_SERVER['HTTP_HOST']) . $custom_error_handler_redirection; } @header('Location: ' . $custom_error_handler_redirection); print <<<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> EOF; print ' <meta http-equiv="Refresh" content="0; url=' . $custom_error_handler_redirection . '">' . "\n"; print <<<EOF <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" /> <title> ... </title> </head> <body> <div> ... </div> </body> </html> EOF; } if (_custom_error_handler_antibomb() !== 0) { die; } if (ERRORNOT_ENABLED !== TRUE) { die; } require_once 'HTTP/Request2.php'; require_once APP_LIB_DIR . '/ErrorNot/errornot.php'; $errornot = new Services_ErrorNot(ERRORNOT_URI, ERRORNOT_API_KEY); $en_bt = '<h1>' . nl2br(htmlspecialchars($errstr)) . '</h1>'; $en_bt .= '<ul>'; foreach ($bt as $trace) { if (empty($trace['file']) || empty($trace['line'])) { continue; } if (strstr(__FILE__, $trace['file']) !== FALSE) { continue; } $en_bt .= '<li>'; $en_bt .= '<b>File:</b> ' . nl2br(htmlspecialchars($trace['file']) . "\n") . '<b>Line:</b> ' . nl2br(htmlspecialchars($trace['line']) . "\n"); if ($trace['function'] !== 'custom_error_handler') { $en_bt .= '<b>Function:</b> ' . nl2br(htmlspecialchars($trace['function']) . "()\n"); } $en_bt .= '</li>'; } $en_bt .= '</ul>'; $en_bt = str_replace("\n", '', $en_bt); if (!empty($_SERVER['REMOTE_ADDR'])) { $uri = 'http://' . rawurlencode($_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI']; } else { $uri = '(commandline)'; } $errornot->notify(substr($errstr, 0, 100), NULL, $en_bt, array('request' => array('uri' => $uri, 'method' => @$_SERVER['REQUEST_METHOD'], 'post' => $_POST, 'get' => $_GET, 'cookies' => $_COOKIE), 'params' => array('svn_user' => @$_SERVER['SVN_USER'])), $_SERVER); die; }
<?php require_once 'HTTP/Request2.php'; require_once dirname(__FILE__) . '/../errornot.php'; require_once 'mock.php'; function myExceptionHandler($e) { if ($e->getMessage() == 'test') { exit(3); } exit(4); } set_exception_handler('myExceptionHandler'); class MockAdapterWithNotify extends Http_Request2_Adapter_Mock { public function sendRequest(HTTP_Request2 $request) { return $this->createResponseFromString("HTTP/1.1 200 OK\nServer: Apache\nOK\n"); } } $mock_network = createMockRequest('test_ok.txt', 'MockAdapterWithNotify'); $errornot = Services_ErrorNot::getInstance(true)->setUrl('http://localhost:3000/')->setApi('test-key')->registerExceptionHandler()->setNetworkAdapter($mock_network); throw new Exception('test'); exit(0);