/** * Redirecciona a un error, ejemplo un 404. * * @param integer $errno * @return void */ public function error($errno) { $response = new Response(); header("HTTP/1.0 {$errno} " . $response->getResponseStatus($errno), true, $errno); /* * Retorna un Response para mostrar el mensaje de que algo salio mal * este solo se muestra cuando esta en produccion. * */ if (!Settings::inDebug()) { Settings::set('ForeverPHPTemplate', true); $response->render('error', new Context(array('message' => 'Oops, al parecer algo salió mal.')))->make(); } }
/** * Permite mostrar un excepción propia. * * @param string $type * @param string $message * @return void */ private static function viewException($type, $message) { $template = 'exception'; $title = 'Excepción'; // 1 es Error if ($type === 1) { $title = 'Error'; } if (Settings::getInstance()->inDebug()) { $contentBuffer = json_decode(ob_get_contents()); // Limpio el buffer de salida previo if (ob_get_length()) { ob_clean(); } Context::useGlobal(false); Context::set('exception', $title); Context::set('details', $message); $response = new Response(); if (is_array($contentBuffer)) { $contentBuffer['ForeverPHPException'] = Context::all(); $response->json($contentBuffer)->make(); } else { // Si hay buffer de salida previo cambio el template if (ob_get_length() != 0) { $template = 'exception-block'; } // Le indico a la vista que haga render usando los templates del framework Settings::getInstance()->set('ForeverPHPTemplate', true); $response->render($template)->make(); } } else { // Termino el buffer de salida y lo limpio ob_end_clean(); // Redirijo a un error 500 return Redirect::error(500); } }
public function make() { $data = array(); if (is_array($this->content)) { $data = $this->content; } else { // Obtiene los datos del contexto $data = Context::all(); } header('HTTP/1.0 ' . $this->statusCode . ' ' . Response::getResponseStatus($this->statusCode), true, $this->statusCode); header('Content-type: application/json; charset: ' . $this->charset); header('Accept-Charset: ' . $this->charset); // Comienza la captura del buffer de salida ob_start(); // Retorna los datos en formato JSON echo json_encode($data); }