Beispiel #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("");
         }
     }
 }
Beispiel #2
0
 /**
  * @param          $route
  * @param Request  $request
  * @param Response $response
  */
 private function handleRoute($route, Request $request, Response $response)
 {
     $theRoute = $this->routeCollection->get($route['_route']);
     $controllerClass = $theRoute->getOption('karmaController');
     $action = $theRoute->getOption('karmaAction');
     $controller = new $controllerClass($this->dispatcher, $request, $response);
     /* @var $controller \ThinFrame\Karma\ViewController\AbstractController */
     unset($route['_route']);
     $this->dispatcher->trigger($controllerActionEvent = new ControllerActionEvent($request, $response, $controller, $action, $route));
     $actionResponse = $controller->trigger($action, $controllerActionEvent->getArguments());
     $this->dispatcher->trigger($controllerResponseEvent = new ControllerResponseEvent($request, $response, $controller, $action, $controllerActionEvent->getArguments(), $actionResponse));
     $response->setContent((string) $controllerResponseEvent->getActionResponse());
 }