/** * Runs the whole logic. It is fajr's main() * * @returns void */ public function run() { try { $trace = $this->injector->getInstance('Trace.class'); $this->statistics = $this->injector->getInstance('Statistics.class'); $this->context = $this->injector->getInstance('Context.class'); $session = $this->context->getSessionStorage(); $response = $this->context->getResponse(); $loginManager = new LoginManager($session, $this->context->getRequest()); // we are going to log in, so we get a clean session // this needs to be done before a connection // is created, because we pass cookie file name // that contains session_id into AIS2CurlConnection if ($loginManager->shouldLogin()) { $session->regenerate(true); } $connection = $this->provideConnection(); $this->setResponseFields($response); $this->runLogic($trace, $connection); } catch (LoginException $e) { if ($connection) { FajrUtils::logout($connection); } $this->setException($e); } catch (SecurityException $e) { $this->logSecurityException($e); if (!FajrConfig::get('Debug.Exception.ShowStacktrace')) { die("Internal error"); } else { die($e); } } catch (Exception $e) { $this->setException($e); // Note: We MUST unset this exception, because it's // stacktrace holds cyclic references to context // and therefore the order of destruction of all objects // is really random. unset($e); } if ($trace !== null) { $trace->tlog("everything done, rendering template"); if ($trace instanceof \fajr\ArrayTrace) { $response->set('trace', $trace); } else { $response->set('trace', null); } } $this->render($this->context->getResponse()); }