/** * Render an error page. */ public function render() { $error = $this->getError(); $messageBox = new Template('sledgehammer/mvc/templates/httperror.php', $error); $messageBox->render(); foreach ($this->options as $option => $value) { switch ((string) $option) { case 'notice': case 'warning': $function = $option; if (is_array($value)) { call_user_func_array($function, $value); } else { call_user_func($function, $value); } break; case 'exception': \Sledgehammer\report_exception($value); break; default: \Sledgehammer\notice('Unknown option: "' . $option . '"', array('value' => $value)); break; } } }
public function __toString() { try { return \Sledgehammer\component_to_string($this); } catch (Exception $e) { \Sledgehammer\report_exception($e); return ''; } }
private function assertEqualTokenizer($filename) { $content = file_get_contents($filename); //Framework::$autoLoader->getFilename('Sledgehammer\GoogleAnalytics'); try { $tokenIterator = new PhpTokenizer($content); $mergedTokens = ''; $tokens = []; foreach ($tokenIterator as $token) { $mergedTokens .= $token[1]; $tokens[] = $token; } $this->assertSame($content, $mergedTokens, 'Input should match all tokens combined (file: "' . $filename . '")'); } catch (Exception $e) { \Sledgehammer\report_exception($e); ob_flush(); $this->fail($e->getMessage()); } }
public function __toString() { try { ob_start(); $this->render(); return ob_get_clean(); } catch (Exception $e) { \Sledgehammer\report_exception($e); return ''; } }
/** * Write session-data for the given $id. * * @param string $id * @param string $gegevens * * @return bool */ public function write($id, $gegevens) { try { $db = Connection::instance($this->dbLink); $result = $db->query('REPLACE INTO ' . $db->quoteIdentifier($this->table) . ' VALUES (' . $db->quote($id) . ', "' . time() . '", ' . $db->quote($gegevens) . ')'); if ($result) { return true; } } catch (\Exception $e) { \Sledgehammer\report_exception($e); } return false; }
/** * Allow the SQL object to be used as string. * * @return string */ public function __toString() { try { return $this->compose(); } catch (Exception $e) { // __toString must not throw an exception \Sledgehammer\report_exception($e); return ''; } catch (\Throwable $e) { \Sledgehammer\report_exception($e); return ''; } }
/** * Reports the error/exception to the ErrorHandler and returns the error as Json object. * The javascript client should detect and report the error to the user: * if (result.success !== true) { alert(result.error); }. * * @param string|Exception $error The error message or Exception * @param int $http The HTTP status code (defaults to 400 Bad Request) * * @return Json */ public static function error($error, $http = 400) { if (headers_sent() === false && DebugR::isEnabled()) { ErrorHandler::instance()->html = false; } if ($error instanceof Exception) { \Sledgehammer\report_exception($error); $error = $error->getMessage(); } else { \Sledgehammer\warning($error); } return new self(array('success' => false, 'error' => $error), array('http' => array('Status' => $http . ' ' . Framework::$statusCodes[$http], 'Content-Type' => ErrorHandler::instance()->html ? 'text/html; charset=utf-8' : 'application/json'))); }
/** * Returns the response body. * * @return string */ public function __toString() { try { return $this->getContent(); } catch (Exception $e) { \Sledgehammer\report_exception($e); return ''; } }
/** * Report an exception. * * @param Exception $exception */ function report_exception($exception) { Sledgehammer\report_exception($exception); }