Exemple #1
0
 /**
  * @param ActionEvent $event
  */
 public function onAction(ActionEvent $event)
 {
     if ($this->getParameterResolver()->resolveApi()) {
         return;
     }
     $form = $event->getForm();
     if ($form !== null && !$form->isValid()) {
         $view = View::create($form);
     } else {
         $route = $this->getParameterResolver()->resolveRedirectRoute();
         $routeParameters = [];
         if ($form !== null) {
             $routeParameters = $this->getParameterResolver()->resolveRedirectRouteParameters(is_object($data = $form->getData()) ? $data : null, $this->getParameterResolver()->resolveRedirectRouteParametersForward());
         }
         $view = View::createRouteRedirect($route, $routeParameters);
     }
     $event->setView($view);
 }
Exemple #2
0
 /**
  * @param ActionEvent $event
  */
 public function onAction(ActionEvent $event)
 {
     if (!$this->getParameterResolver()->resolveApi()) {
         return;
     }
     $form = $event->getForm();
     if ($form === null) {
         $view = View::create();
     } elseif (!$form->isValid()) {
         $view = View::create($form, Response::HTTP_BAD_REQUEST);
     } else {
         $headers = [];
         $statusCode = $event->getStatusCode();
         $data = $statusCode === Response::HTTP_NO_CONTENT ? null : $form->getData();
         if ($statusCode === Response::HTTP_CREATED) {
             $headers['Location'] = $this->urlGenerator->generate($this->getParameterResolver()->resolveLocationRoute(), $this->getParameterResolver()->resolveLocationRouteParameters($form->getData()));
         }
         $view = View::create($data, $statusCode, $headers);
     }
     $event->setView($view);
 }
Exemple #3
0
 public function testView()
 {
     $this->event->setView($view = $this->createViewMock());
     $this->assertSame($view, $this->event->getView());
     $this->assertTrue($this->event->isPropagationStopped());
 }
Exemple #4
0
 public function testView()
 {
     $this->event->setView($view = $this->createViewMock());
     $this->assertSame($view, $this->event->getView());
 }
Exemple #5
0
 /**
  * @param string             $action
  * @param FormInterface|null $form
  * @param int                $statusCode
  *
  * @return Response
  */
 protected function processAction($action, FormInterface $form = null, $statusCode = Response::HTTP_NO_CONTENT)
 {
     $statusCode = $this->getParameterResolver()->resolveStatusCode($statusCode);
     $this->getRestEventDispatcher()->dispatch(RestEvents::ACTION, $event = new ActionEvent($this->resource, $action, $form, $statusCode));
     $view = $event->getView();
     $statusCode = $view->getStatusCode();
     return $statusCode >= 300 && $statusCode < 400 ? $this->handleView($view) : $this->processView($action, $view);
 }