public function dispatchAppServer($context) { $_ENV = $_SERVER = $context['env']; @parse_str($_ENV['QUERY_STRING'], $_GET); $_GET['ak'] = $_ENV['PATH_INFO']; Ak::unsetStaticVar('AkRequestSingleton'); Ak::unsetStaticVar('AkRouterSingleton'); Ak::unsetStaticVar('AkUrlWriterSingleton'); AkConfig::setOption('Request.remote_ip', '127.0.0.1'); try { $time_start = microtime(true); AK_ENABLE_PROFILER && AkDebug::profile(__CLASS__ . '::' . __FUNCTION__ . '() call'); $this->Request = AkRequest::getInstance(); $this->Response = new AkResponse(); $path = ltrim(str_replace('..', '.', $context['env']['REQUEST_URI']), '/. '); if (empty($path) && file_exists(AK_PUBLIC_DIR . DS . 'index.html')) { $Controller = new AkActionController(); $Controller->Response = $this->Response; $Controller->renderText(file_get_contents(AK_PUBLIC_DIR . DS . 'index.html')); return $Controller->Response; } elseif (!empty($path) && file_exists(AK_PUBLIC_DIR . DS . $path)) { $Controller = new AkActionController(); $Controller->Response = $this->Response; $Controller->sendFile(AK_PUBLIC_DIR . DS . $path, array('stream' => false)); return $Controller->Response; } else { if ($this->Controller = $this->Request->recognize()) { $this->Controller->ak_time_start = $time_start; AK_ENABLE_PROFILER && AkDebug::profile('Request::recognize() completed'); $this->Controller->process($this->Request, $this->Response); } return $this->Response; } } catch (Exception $e) { if (isset($this->Controller) && method_exists($this->Controller, 'render_error')) { $this->Controller->render_error($e); } else { $ExceptionDispatcher = new AkExceptionDispatcher(); $ExceptionDispatcher->renderException($e); } } }
public function mapRoutes($Router = null) { if (empty($Router)) { $Router = AkRouter::getInstance(); } try { $this->checkForRoutedRequests($Router); } catch (Exception $e) { if (AK_TEST_MODE) { throw $e; } else { $ExceptionDispatcher = new AkExceptionDispatcher(); $ExceptionDispatcher->renderException($e); return false; } } return true; }