public function render($vars = null) { // Autoloads // juste avant l'affichage pour que les components soit tous déjà chargés pour les transmitions aux helpers foreach ($this->_params["helpers"] as $key => $value) { if (is_numeric($key)) { $this->load($value); } else { $this->load($key, $value); } } if ($vars != null) { extract($vars); } if (file_exists("app/frontend/views/themes/" . $this->_defaultTheme . '/index.php')) { include "app/frontend/views/themes/" . $this->_defaultTheme . '/index.php'; } else { Error::render(3, $this->_defaultTheme); } }
/** * @expectedException Error */ public function testException() { $e = new Error(400, "This is message", 8); $e->render(); }
/** * Replaces Kohana's `Kohana::exception_handler()` method. This does the * same thing, but also adds email functionality and the ability to perform * an action in response to the exception. These actions and emails are * customizable per type in the config file for this module. * * @uses Kohana::exception_text * @param \Exception $e * @internal param \exception $object object * @return boolean */ public static function handler(Exception $e) { try { $error = new Error(); // Get the exception information $error->exception = $e; $error->type = get_class($e); $error->code = $e->getCode(); $error->message = $e->getMessage(); $error->file = $e->getFile(); $error->line = $e->getLine(); $error->request_initial = Request::initial(); // Create a text version of the exception $error->text = Kohana_Exception::text($e); if (Kohana::$is_cli) { // Display the text of the exception echo "\n{$error->text}\n"; } // Get the exception backtrace $error->trace = $e->getTrace(); if ($e instanceof ErrorException) { if (version_compare(PHP_VERSION, '5.3', '<')) { // Workaround for a bug in ErrorException::getTrace() that exists in // all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895 for ($i = count($error->trace) - 1;$i > 0;--$i) { if (isset($error->trace[$i - 1]['args'])) { // Re-position the args $error->trace[$i]['args'] = $error->trace[$i - 1]['args']; // Remove the args unset($error->trace[$i - 1]['args']); } } } } if (!headers_sent() and (Kohana::$is_cli === false)) { // Make sure the proper content type is sent with a 500 status header('Content-Type: text/html; charset=' . Kohana::$charset, true, 500); } // Get the contents of the output buffer $error->display = $error->render(); // Log the error $error->log(); // Email the error $error->email(); // Respond to the error $error->action(); return true; } catch (Exception $e) { // Log an error. if (is_object(Kohana::$log)) { // Create a text version of the exception $error = Kohana_Exception::text($e); // Add this exception to the log Kohana::$log->add(Log::ERROR, $error); // Make sure the logs are written Kohana::$log->write(); } // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text header('HTTP/1.1 500 Internal Server Error'); echo "Unknown Error - Exception thrown in Error::handler()"; // Exit with an error status exit(1); } }
/** * Permet de charger la View avec son template * @return string Contenu de la View après son rendu, et avec le template. Oui monsieur !!! =) */ public function load() { header('HTTP/1.0 ' . $this->httpCode . ' ' . $this->httpCodes[$this->httpCode]); $viewFile = APP . '/View/' . Path::ds($this->viewName) . '.php'; $templateFile = APP . '/Template/' . Path::ds($this->templateName) . '.php'; if (file_exists($viewFile)) { extract(array_merge(compact('this'), $this->vars)); ob_start(); include $viewFile; $content = ob_get_clean(); if (file_exists($templateFile)) { include $templateFile; return ob_get_clean(); } else { return Error::render('missingTemplate', ['template' => $this->templateName]); } } else { return Error::render('missingView', ['view' => $this->viewName]); } }
/** * Carrega a página de erro de acordo com as configurações e mata a execução * @param object $error instância de Exception * @return void */ private function loadError($error) { Error::render($error->getCode(), $error->getMessage(), $error->getFile(), $error->getLine(), $error->getTraceAsString(), method_exists($error, 'getDetails') ? $error->getDetails() : ''); }