public function run()
{
try {
// register the default autoloader
require SERVER_AUTOLOADER;
// register shutdown handler
set_error_handler(array(&$this, 'errorHandler'));
register_shutdown_function(array(&$this, 'shutdown'));
// initialize the array for the errors
$this->errors = array();
// synchronize the application instance and register the class loaders
$application = $this->application;
$application->registerClassLoaders();
// synchronize the valves, servlet request/response
$valves = $this->valves;
$servletRequest = $this->servletRequest;
$servletResponse = $this->servletResponse;
// load the session and the authentication manager
$sessionManager = $application->search(SessionManagerInterface::IDENTIFIER);
$authenticationManager = $application->search(AuthenticationManagerInterface::IDENTIFIER);
// inject the sapplication and servlet response
$servletRequest->injectContext($application);
$servletRequest->injectResponse($servletResponse);
$servletRequest->injectSessionManager($sessionManager);
$servletRequest->injectAuthenticationManager($authenticationManager);
// prepare the request instance
$servletRequest->prepare();
// initialize static request and application context
RequestHandler::$requestContext = $servletRequest;
RequestHandler::$applicationContext = $application;
// process the valves
foreach ($valves as $valve) {
$valve->invoke($servletRequest, $servletResponse);
if ($servletRequest->isDispatched() === true) {
break;
}
}
// profile the request if the profile logger is available
if ($profileLogger = $application->getInitialContext()->getLogger(LoggerUtils::PROFILE)) {
$profileLogger->appendThreadContext('request-handler');
$profileLogger->debug($servletRequest->getUri());
}
} catch (\Exception $e) {
$this->addError(ErrorUtil::singleton()->fromException($e));
}
// re-attach request and response instances
$this->servletRequest = $servletRequest;
$this->servletResponse = $servletResponse;
}