Example #1
0
 /**
  * Handles react request and create http compliant request/response objects
  *
  * @param ReactRequestEvent $event
  */
 public function onRequest(ReactRequestEvent $event)
 {
     $event->stopPropagation();
     $request = RequestFactory::createFromReact($event->getRequest(), $event->getData());
     $response = new Response();
     $response->setReactResponse($event->getResponse());
     try {
         $this->dispatcher->trigger($requestEvent = new HttpRequestEvent($request, $response));
         if ($requestEvent->shouldPropagate()) {
             $response->setStatusCode(new StatusCode(StatusCode::NOT_FOUND))->setContent("");
         }
     } catch (AbstractHttpException $e) {
         $this->dispatcher->trigger($exceptionEvent = new HttpExceptionEvent($e, $request, $response));
         if ($exceptionEvent->shouldPropagate()) {
             $response->setStatusCode($e->getStatusCode());
             if (trim($e->getMessage()) != '') {
                 $response->setContent($e->getMessage());
             } else {
                 $response->getHeaders()->remove('Content-Type');
                 $response->setContent("");
             }
         }
     } catch (\Exception $e) {
         $this->dispatcher->trigger($event = new UnknownHttpExceptionEvent($e, $request, $response));
         if ($event->shouldPropagate()) {
             $response->setStatusCode(new StatusCode(StatusCode::INTERNAL_SERVER_ERROR));
             $response->getHeaders()->remove('Content-Type');
             $response->setContent("");
         }
     }
 }