Created
January 3, 2011 23:59
-
-
Save bermi/764204 to your computer and use it in GitHub Desktop.
dispatchAppServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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