/** * Send a response with a generic error message. */ public function outputErrors() { // if accept text/html if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) { require_once JELIX_LIB_CORE_PATH . 'responses/jResponseBasicHtml.class.php'; $response = new \jResponseBasicHtml(); $response->outputErrors(); } else { // output text response header("HTTP/{$this->httpVersion} 500 Internal jelix error"); header('Content-type: text/plain'); echo App::router()->getGenericErrorMessage(); } }
/** * output messages to the given response * @param jResponseBasicHtml $response */ function output($response) { //if (! ($response instanceof jResponseBasicHtml) if (!count($this->messages)) { return; } $type = $response->getType(); if ($type != 'html' && $type != 'htmlfragment') { return; } $src = '<script type="text/javascript">//<![CDATA[ if(console){'; foreach ($this->messages as $m) { switch ($m->getCategory()) { case 'warning': $src .= 'console.warn("'; break; case 'error': $src .= 'console.error("'; break; case 'warning': case 'notice': $src .= 'console.debug("'; break; default: $src .= 'console.info("'; break; } $src .= str_replace(array('"', "\n", "\r", "\t"), array('\\"', '\\n', '\\r', '\\t'), $m->getFormatedMessage()); $src .= '");'; } $src .= '} //]]> </script>'; //$src .= '}else{alert("there are some errors or me, you should activate Firebug to see them");}</script>'; $response->addContent($src); }
/** * constructor; * setup the charset, the lang, the template engine */ function __construct() { $this->body = new jTpl(); parent::__construct(); }