public function _start()
{
$dispatched = false;
$self = $this;
$request = $this->request();
$response = $this->response();
$router = $this->router();
// Flush any existing output
if (ob_get_length() > 0) {
$response->write(ob_get_clean());
}
// Enable output buffering
ob_start();
// Enable error handling
$this->handleErrors($this->get('flight.handle_errors'));
// Allow post-filters to run
$this->after('start', function () use($self) {
$self->stop();
});
// Set case-sensitivity
$router->case_sensitive = $this->get('flight.case_sensitive');
// Route the request
while ($route = $router->route($request)) {
$params = array_values($route->params);
// Add route info to the parameter list
if ($route->pass) {
$params[] = $route;
}
// Call route handler
$continue = $this->dispatcher->execute($route->callback, $params);
$dispatched = true;
if (!$continue) {
break;
}
$router->next();
$dispatched = false;
}
if (!$dispatched) {
$this->notFound();
}
}