function test_is_error() { $this->assertFalse(No2_HTTP::is_error(399)); // before inf limit $this->assertTrue(No2_HTTP::is_error(400)); // inferior limit $this->assertTrue(No2_HTTP::is_error(431)); // mid. $this->assertTrue(No2_HTTP::is_error(500)); // mid. $this->assertTrue(No2_HTTP::is_error(503)); // superior limit $this->assertFalse(No2_HTTP::is_error(600)); // after sup limit }
No2_Logger::err(__FILE__ . ': ' . $_->getMessage()); header('HTTP/1.1 500 Internal Server Error'); ?> <html> <head><title>500 Internal Server Error</title></head> <body> <h1>500 Internal Server Error</h1> <p>Please contact the site administrator</p> </body> </html> <?php die; } } $view = $controller->view(); if (No2_HTTP::is_error($view->status()) && !$controller->can_render_errors()) { /* * The controller declined error handling, so we load the default error * controller to generate the response. */ require_once APPDIR . '/controllers/error.class.php'; $controller = new ErrorController($view->status()); unset($view); goto invoke_it; } /* from this point, $controller and $view are set and valid. */ /* * Here we know the status code, log the request and render the requested ressource. */ No2_Logger::info("{$_SERVER['REMOTE_ADDR']} - {$_SERVER['REQUEST_METHOD']} - {$_SERVER['REQUEST_URI']} - {$view->status()}"); /* kindly ask the view to render the response */
/** * Render a zone. * * This method is the main method to generate output. * * @param $zone * The zone to render. The default, `page', is the root zone for * rendering. When the `page' zone is asked to be rendered, HTTP headers * are set. render_error() or render_redirect() can be called * depending on the __http_status property of this object. * * @see No2_AbstractController::pre_render(), render_error(), * render_redirect() */ public function render($zone = 'page') { No2_Logger::no2debug(get_class($this) . "::render: zone={$zone}"); if ($zone == 'page') { $this->set_http_header(); // on error or redirect call the proper methods. if (No2_HTTP::is_error($this->status())) { $this->render_error(); return; } else { if (No2_HTTP::is_redirection($this->status())) { $this->render_redirect(); return; } } } /* "normal" render code. */ $tpl_file = $this->controller->pre_render($zone); if (!is_null($tpl_file)) { No2_Logger::no2debug(get_class($this) . "::render: rendering file {$tpl_file}"); $this->_render($tpl_file); } }