/** * @param string $endpoint * @param Request $request * @return Response */ public function apiAction($endpoint, Request $request) { $session = $request->getSession(); if ($session && $session->isStarted()) { $session->save(); } if ($request->getMethod() !== Request::METHOD_GET) { throw new MethodNotAllowedHttpException(array(Request::METHOD_GET)); } try { $endpoint = $this->endpointManager->getEndpoint($endpoint); } catch (\InvalidArgumentException $e) { throw new NotFoundHttpException('Not found', $e); } return $endpoint->createServiceDescription($this->urlGenerator->generate('tq_extdirect_router', array('endpoint' => $endpoint->getId())), $request->getRequestFormat('js')); }
/** * @param string $endpoint * @param Request $request * @return Response */ public function routerAction($endpoint, Request $request) { $request->setRequestFormat($request->getContentType()); if ($request->getMethod() !== Request::METHOD_POST) { throw new MethodNotAllowedHttpException(array(Request::METHOD_POST)); } try { $endpoint = $this->endpointManager->getEndpoint($endpoint); } catch (\InvalidArgumentException $e) { throw new NotFoundHttpException('Not Found', $e); } try { return $endpoint->handleRequest($request); } catch (BadRequestException $e) { throw new BadRequestHttpException('Bad Request', $e); } }