예제 #1
0
 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response)
 {
     $criteria = $request->getCriteria();
     $changes = $request->getChanges();
     if ($this->criteriaValidator->isValid($criteria)) {
         if ($this->changesValidator->isValid($changes)) {
             $result = $this->service->handle($this->criteriaValidator->getValid(), $this->changesValidator->getValid());
             $response->setResult($result);
         } else {
             $response->setChangesErrors($this->changesValidator->getErrors());
         }
     } else {
         $response->setCriteriaErrors($this->criteriaValidator->getErrors());
     }
     $response->setCriteria($criteria);
     $response->setChanges($changes);
     $response->setValidCriteria($this->criteriaValidator->getValid());
     $response->setValidChanges($this->changesValidator->getValid());
     return $response;
 }
예제 #2
0
 /**
  * @param MvcEvent $e
  * @return mixed|\Zend\Http\Response|ViewModelInterface
  */
 public function onDispatch(MvcEvent $e)
 {
     if (!empty($this->options['allowedMethods']) && !in_array($this->sebaksRequest->getMethod(), $this->options['allowedMethods'])) {
         return $this->error->methodNotAllowed();
     }
     $e->setParam('sebaksRequest', $this->sebaksRequest);
     $e->setParam('sebaksResponse', $this->sebaksResponse);
     $routeName = $e->getRouteMatch()->getMatchedRouteName();
     $this->getEventManager()->trigger("dispatch.{$routeName}.pre", $e);
     $this->controller->dispatch($this->sebaksRequest, $this->sebaksResponse);
     $this->getEventManager()->trigger("dispatch.{$routeName}.post", $e);
     $criteriaErrors = $this->sebaksResponse->getCriteriaErrors();
     if (!empty($criteriaErrors)) {
         return $this->error->notFoundByRequestedCriteria($criteriaErrors);
     }
     $changesErrors = $this->sebaksResponse->getChangesErrors();
     $redirectTo = $this->sebaksResponse->getRedirectTo();
     if (empty($changesErrors) && !empty($redirectTo)) {
         if (is_array($redirectTo)) {
             if (!isset($redirectTo['route'])) {
                 throw new \RuntimeException('Missing required parameter route');
             }
             $routeParams = isset($redirectTo['params']) ? $redirectTo['params'] : [];
             $routeOptions = isset($redirectTo['options']) ? $redirectTo['options'] : [];
             return $this->redirect()->toRoute($redirectTo['route'], $routeParams, $routeOptions);
         } else {
             return $this->redirect()->toRoute($redirectTo);
         }
     }
     if (!empty($changesErrors)) {
         $result = $this->error->changesErrors($changesErrors);
         if ($result instanceof Response) {
             return $result;
         }
     }
     $this->viewModel->setVariables($this->sebaksResponse->toArray());
     $e->setResult($this->viewModel);
     return $this->viewModel;
 }