Skip to content

Instantly share code, notes, and snippets.

@bermi
Created January 3, 2011 23:59
Show Gist options
  • Save bermi/764204 to your computer and use it in GitHub Desktop.
Save bermi/764204 to your computer and use it in GitHub Desktop.
dispatchAppServer
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{
$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.$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->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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment