protected function generateResponseForException(RhubarbException $er)
 {
     $urlHandler = UrlHandler::getExecutingUrlHandler();
     if ($urlHandler) {
         return $urlHandler->generateResponseForException($er);
     } else {
         $response = new HtmlResponse();
         $response->setContent("<p>The application failed to start. Please consult the shutdown error log for more details");
         return $response;
     }
 }
 public function generateResponse($request = null)
 {
     if (class_exists("Rhubarb\\Crown\\Layout\\LayoutModule")) {
         LayoutModule::disableLayout();
     }
     $schemas = SolutionSchema::getAllSchemas();
     foreach ($schemas as $schema) {
         $schema->checkModelSchemas();
     }
     $response = new HtmlResponse();
     $response->setContent("Done");
     return $response;
 }
 /**
  * Return the response when appropriate or false if no response could be generated.
  *
  * @param mixed $request
  * @param string $currentUrlFragment
  * @return bool
  */
 protected function generateResponseForRequest($request = null, $currentUrlFragment = "")
 {
     $response = new HtmlResponse();
     $response->setContent("child");
     return $response;
 }
Example #4
0
 public function generateResponseForException(RhubarbException $er)
 {
     $context = Application::current()->context();
     if ($context->isXhrRequest()) {
         $response = new Response();
     } else {
         $response = new HtmlResponse();
     }
     $response->setResponseCode(Response::HTTP_STATUS_SERVER_ERROR_GENERIC);
     $response->setContent($er->getPublicMessage());
     return $response;
 }
Example #5
0
 /**
  * Generates the response content for the client.
  *
  * This is normally called by platform/execute-http.php and must be called after all
  * modules have been registered to guarantee the correct output.
  *
  * @static
  * @param Request $request
  * @return string|Response
  */
 public final function generateResponseForRequest(Request $request)
 {
     $this->setAsRunningApplication();
     $this->request = $request;
     $this->activeRequest = $request;
     $additionalData = [];
     if ($request instanceof WebRequest) {
         if (!empty($request->GetData)) {
             $additionalData = $request->GetData;
         }
     }
     Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, function () use($request) {
         if ($request instanceof WebRequest) {
             return "Generating response for url " . $request->urlPath;
         }
         if ($request instanceof CliRequest) {
             return "Starting CLI response";
         }
         return "";
     }, "ROUTER", $additionalData);
     Log::indent();
     // an empty-string Response to fall back on if nothing else is generated
     $response = new HtmlResponse();
     $response->setContent('');
     $filterResponse = true;
     try {
         // Iterate over each handler and ask them to generate a response.
         // If they do return a response we return that and exit the loop.
         // If they return false then we assume they couldn't handle the URL
         // and continue to the next handler.
         foreach ($this->rootHandlers as $handler) {
             $generatedResponse = $handler->generateResponse($request);
             if ($generatedResponse !== false) {
                 Log::debug(function () use($handler) {
                     return ["Handler `" . get_class($handler) . "` generated response.", []];
                 }, "ROUTER");
                 // it should be preferred for a handler to return a Response object,
                 // but checking this here retains the option for them to just return
                 // their output
                 if ($generatedResponse instanceof Response) {
                     $response = $generatedResponse;
                 } else {
                     $response->setContent($generatedResponse);
                 }
                 break;
             }
         }
     } catch (ForceResponseException $er) {
         // Clear any previous output in buffers to ensure we only send the forced response
         while (ob_get_level()) {
             ob_end_clean();
         }
         $response = $er->getResponse();
         $filterResponse = false;
     } catch (StopGeneratingResponseException $er) {
         $filterResponse = false;
     } catch (RhubarbException $er) {
         $handler = $this->container()->getInstance(ExceptionHandler::class);
         $response = $handler->processException($er);
     } catch (\Exception $er) {
         $handler = $this->container()->getInstance(ExceptionHandler::class);
         $response = $handler->processException(new NonRhubarbException($er));
     }
     if ($filterResponse) {
         Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters started", "ROUTER");
         Log::indent();
         $filters = $this->getAllResponseFilters();
         foreach ($filters as $filter) {
             $response = $filter->processResponse($response);
         }
         Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters finished", "ROUTER");
         Log::outdent();
     }
     Log::performance("Response generated", "ROUTER");
     Log::outdent();
     return $response;
 }
Example #6
0
 /**
  * Generates the response content for the client.
  *
  * This is normally called by platform/execute-http.php and must be called after all
  * modules have been registered to guarantee the correct output.
  *
  * @static
  * @param Request\Request $request
  * @return string
  */
 public static function generateResponseForRequest(Request\Request $request)
 {
     // Set the current request to be this one.
     $context = new Context();
     $context->Request = $request;
     $additionalData = [];
     if ($request instanceof WebRequest) {
         if (!empty($request->GetData)) {
             $additionalData = $request->GetData;
         }
     }
     Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, function () use($request) {
         if ($request instanceof WebRequest) {
             return "Generating response for url " . $request->UrlPath;
         }
         if ($request instanceof CliRequest) {
             return "Starting CLI response";
         }
         return "";
     }, "ROUTER", $additionalData);
     Log::indent();
     $handlers = self::getAllUrlHandlers();
     // an empty-string Response to fall back on if nothing else is generated
     $response = new HtmlResponse();
     $response->SetContent('');
     $filterResponse = true;
     try {
         // Iterate over each handler and ask them to generate a response.
         // If they do return a response we return that and exit the loop.
         // If they return false then we assume they couldn't handle the URL
         // and continue to the next handler.
         foreach ($handlers as $handler) {
             $generatedResponse = $handler->generateResponse($request);
             if ($generatedResponse !== false) {
                 Log::Debug(function () use($handler) {
                     return ["Handler `" . get_class($handler) . "` generated response.", []];
                 }, "ROUTER");
                 // it should be preferred for a handler to return a Response object,
                 // but checking this here retains the option for them to just return
                 // their output
                 if ($generatedResponse instanceof Response) {
                     $response = $generatedResponse;
                 } else {
                     $response->setContent($generatedResponse);
                 }
                 break;
             }
         }
     } catch (ForceResponseException $er) {
         $response = $er->getResponse();
         $filterResponse = false;
     } catch (StopGeneratingResponseException $er) {
         $filterResponse = false;
     } catch (RhubarbException $er) {
         $response = ExceptionHandler::processException($er);
     } catch (\Exception $er) {
         $response = ExceptionHandler::processException(new NonRhubarbException($er));
     }
     if ($filterResponse) {
         Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters started", "ROUTER");
         Log::indent();
         $filters = self::getAllResponseFilters();
         foreach ($filters as $filter) {
             $response = $filter->processResponse($response);
         }
         Log::createEntry(Log::PERFORMANCE_LEVEL | Log::DEBUG_LEVEL, "Output filters finished", "ROUTER");
         Log::outdent();
     }
     Log::performance("Response generated", "ROUTER");
     Log::outdent();
     return $response;
 }
Example #7
0
 public function generateResponseForException(RhubarbException $er)
 {
     $response = new HtmlResponse();
     $response->setContent($er->getPublicMessage());
     return $response;
 }