public function processRequest(AphrontRequest $request, PhutilDeferredLog $access_log, AphrontHTTPSink $sink, MultimeterControl $multimeter) { $this->setRequest($request); list($controller, $uri_data) = $this->buildController(); $controller_class = get_class($controller); $access_log->setData(array('C' => $controller_class)); $multimeter->setEventContext('web.' . $controller_class); $request->setURIMap($uri_data); $controller->setRequest($request); // If execution throws an exception and then trying to render that // exception throws another exception, we want to show the original // exception, as it is likely the root cause of the rendering exception. $original_exception = null; try { $response = $controller->willBeginExecution(); if ($request->getUser() && $request->getUser()->getPHID()) { $access_log->setData(array('u' => $request->getUser()->getUserName(), 'P' => $request->getUser()->getPHID())); $multimeter->setEventViewer('user.' . $request->getUser()->getPHID()); } if (!$response) { $controller->willProcessRequest($uri_data); $response = $controller->handleRequest($request); } } catch (Exception $ex) { $original_exception = $ex; $response = $this->handleException($ex); } try { $response = $controller->didProcessRequest($response); $response = $this->willSendResponse($response, $controller); $response->setRequest($request); $unexpected_output = PhabricatorStartup::endOutputCapture(); if ($unexpected_output) { $unexpected_output = pht("Unexpected output:\n\n%s", $unexpected_output); phlog($unexpected_output); if ($response instanceof AphrontWebpageResponse) { echo phutil_tag('div', array('style' => 'background: #eeddff;' . 'white-space: pre-wrap;' . 'z-index: 200000;' . 'position: relative;' . 'padding: 8px;' . 'font-family: monospace'), $unexpected_output); } } $sink->writeResponse($response); } catch (Exception $ex) { if ($original_exception) { throw $original_exception; } throw $ex; } return $response; }
private static function writeResponse(AphrontHTTPSink $sink, AphrontResponse $response) { $unexpected_output = PhabricatorStartup::endOutputCapture(); if ($unexpected_output) { $unexpected_output = pht("Unexpected output:\n\n%s", $unexpected_output); phlog($unexpected_output); if ($response instanceof AphrontWebpageResponse) { echo phutil_tag('div', array('style' => 'background: #eeddff;' . 'white-space: pre-wrap;' . 'z-index: 200000;' . 'position: relative;' . 'padding: 8px;' . 'font-family: monospace'), $unexpected_output); } } $sink->writeResponse($response); }
if ($request->getUser() && $request->getUser()->getPHID()) { $access_log->setData(array('u' => $request->getUser()->getUserName(), 'P' => $request->getUser()->getPHID())); } if (!$response) { $controller->willProcessRequest($uri_data); $response = $controller->processRequest(); } } catch (Exception $ex) { $original_exception = $ex; $response = $application->handleException($ex); } try { $response = $controller->didProcessRequest($response); $response = $application->willSendResponse($response, $controller); $response->setRequest($request); $unexpected_output = PhabricatorStartup::endOutputCapture(); if ($unexpected_output) { $unexpected_output = "Unexpected output:\n\n{$unexpected_output}"; phlog($unexpected_output); if ($response instanceof AphrontWebpageResponse) { echo phutil_tag('div', array('style' => 'background: #eeddff;' . 'white-space: pre-wrap;' . 'z-index: 200000;' . 'position: relative;' . 'padding: 8px;' . 'font-family: monospace'), $unexpected_output); } } $sink->writeResponse($response); } catch (Exception $ex) { $write_guard->dispose(); $access_log->write(); if ($original_exception) { $ex = new PhutilAggregateException('Multiple exceptions during processing and rendering.', array($original_exception, $ex)); } PhabricatorStartup::didEncounterFatalException('Rendering Exception', $ex, $show_unexpected_traces);
phabricator_startup(); try { PhabricatorStartup::beginStartupPhase('libraries'); PhabricatorStartup::loadCoreLibraries(); PhabricatorStartup::beginStartupPhase('purge'); PhabricatorCaches::destroyRequestCache(); PhabricatorStartup::beginStartupPhase('sink'); $sink = new AphrontPHPHTTPSink(); try { PhabricatorStartup::beginStartupPhase('run'); AphrontApplicationConfiguration::runHTTPRequest($sink); } catch (Exception $ex) { try { $response = new AphrontUnhandledExceptionResponse(); $response->setException($ex); PhabricatorStartup::endOutputCapture(); $sink->writeResponse($response); } catch (Exception $response_exception) { // If we hit a rendering exception, ignore it and throw the original // exception. It is generally more interesting and more likely to be // the root cause. throw $ex; } } } catch (Exception $ex) { PhabricatorStartup::didEncounterFatalException('Core Exception', $ex, false); } function phabricator_startup() { // Load the PhabricatorStartup class itself. $t_startup = microtime(true);