Here is the process to determine the format:
* format defined by the user (with setRequestFormat())
* _format request attribute
* $default
public getRequestFormat ( string $default = 'html' ) : string | ||
$default | string | The default format |
Résultat | string | The request format |
function it_checks_if_its_a_html_request(Request $request) { $request->getRequestFormat()->willReturn('html'); $this->isHtmlRequest()->shouldReturn(true); $request->getRequestFormat()->willReturn('json'); $this->isHtmlRequest()->shouldReturn(false); }
/** * @param $data array * @param format string, either rss or atom */ protected function createFeed(View $view, Request $request) { $feed = new Feed(); $data = $view->getData(); $item = current($data); $annotationData = $this->reader->read($item); if ($item && ($feedData = $annotationData->getFeed())) { $class = get_class($item); $feed->setTitle($feedData->getName()); $feed->setDescription($feedData->getDescription()); $feed->setLink($this->urlGen->generateCollectionUrl($class)); $feed->setFeedLink($this->urlGen->generateCollectionUrl($class, $request->getRequestFormat()), $request->getRequestFormat()); } else { $feed->setTitle('Camdram feed'); $feed->setDescription('Camdram feed'); } $lastModified = null; $accessor = PropertyAccess::createPropertyAccessor(); // Add one or more entries. Note that entries must be manually added once created. foreach ($data as $document) { $entry = $feed->createEntry(); $entry->setTitle($accessor->getValue($document, $feedData->getTitleField())); $entry->setLink($this->urlGen->generateUrl($document)); $entry->setDescription($this->twig->render($feedData->getTemplate(), array('entity' => $document))); if ($accessor->isReadable($document, $feedData->getUpdatedAtField())) { $entry->setDateModified($accessor->getValue($document, $feedData->getUpdatedAtField())); } $feed->addEntry($entry); if (!$lastModified || $entry->getDateModified() > $lastModified) { $lastModified = $entry->getDateModified(); } } $feed->setDateModified($lastModified); return $feed->export($request->getRequestFormat()); }
/** * @Route("/search.{_format}", name="search", * requirements={"_format": "|rss|atom"}, * defaults={"_format": "html"} * ) * @Method({"GET"}) * @Template("ChaosTangentFansubEbooksAppBundle:Search:index.html.twig") */ public function searchAction(Request $request) { $page = $request->query->get('page', 1); $query = $request->query->get('q', null); $seriesResults = []; $lineResults = []; $lineResultsSerialized = ''; $searchTime = 0; if (!empty(trim($query))) { $start = microtime(true); $om = $this->get('doctrine')->getManager(); $lineRepo = $om->getRepository('Entity:Line'); $lineResults = $lineRepo->search($query, $page, 30); if ($page == 1) { $seriesRepo = $om->getRepository('Entity:Series'); $seriesResults = $seriesRepo->search($query); } $searchTime = microtime(true) - $start; $searchEvent = new SearchEvent($query, $page, $searchTime); $this->get('event_dispatcher')->dispatch(SearchEvents::SEARCH, $searchEvent); $serializer = $this->get('jms_serializer'); $context = $this->get('fansubebooks.serializer.context'); $lineResultsSerialized = $serializer->serialize($lineResults->getResults(), 'json', $context); } $viewData = ['query' => $query, 'series_results' => $seriesResults, 'line_results' => $lineResults, 'line_results_serialized' => $lineResultsSerialized, 'search_time' => $searchTime]; if ($request->getRequestFormat() == 'rss') { return $this->render('ChaosTangentFansubEbooksAppBundle:Search:index.rss.twig', $viewData); } else { if ($request->getRequestFormat() == 'atom') { return $this->render('ChaosTangentFansubEbooksAppBundle:Search:index.atom.twig', $viewData); } } return $viewData; }
/** * Returns different responses dependening on the request format. * * @param \Symfony\Component\HttpFoundation\Request $request * The request * * @return \Symfony\Component\HttpFoundation\Response * The response. */ public function format(Request $request) { switch ($request->getRequestFormat()) { case 'json': return new JsonResponse(['some' => 'data']); case 'xml': return new Response('<xml></xml>', Response::HTTP_OK, ['Content-Type' => 'application/xml']); default: return new Response($request->getRequestFormat()); } }
/** * Tries to serialize data that are not API resources (e.g. the entrypoint or data returned by a custom controller). * * @param GetResponseForControllerResultEvent $event * @param Request $request * @param object $controllerResult * * @throws RuntimeException */ private function serializeRawData(GetResponseForControllerResultEvent $event, Request $request, $controllerResult) { if (!$request->attributes->get('_api_respond')) { return; } if (is_object($controllerResult)) { $event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat())); return; } if (!$this->serializer instanceof EncoderInterface) { throw new RuntimeException(sprintf('The serializer instance must implements the "%s" interface.', EncoderInterface::class)); } $event->setControllerResult($this->serializer->encode($controllerResult, $request->getRequestFormat())); }
/** * @Route("/upload", name="picture_create", defaults={"_format": "html"}) */ public function uploadAction(Request $request) { $format = $request->getRequestFormat(); $em = $this->getDoctrine()->getManager(); $picture = new Picture(); $form = $this->createForm(PictureType::class, $picture); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isSubmitted()) { if ($form->isValid()) { $picture->setUser($this->get('security.token_storage')->getToken()->getUser()); $em->persist($picture); $em->flush(); if ($request->isXmlHttpRequest()) { $lReturn = array(); //use renderview instead of render, because renderview returns the rendered template $pictureArray = array('id' => $picture->getId()); $lReturn['picture'] = $pictureArray; $lReturn['rendered'] = $this->renderView('pictures/_singlePictureCard.html.twig', array('picture' => $picture)); return new Response(json_encode($lReturn), 200, array('Content-Type' => 'application/json')); } return $this->redirectToRoute('homepage'); } if ($request->isXmlHttpRequest()) { return $this->render('pictures/_pictureForm.html.twig', array('pictureForm' => $form->createView()), new Response(null, 422)); } return $this->render('pictures/create.html.twig', array('pictureForm' => $form->createView())); } } if ($request->isXmlHttpRequest()) { return $this->render('pictures/_pictureForm.html.twig', array('pictureForm' => $form->createView())); } return $this->render('pictures/create.html.twig', array('pictureForm' => $form->createView())); }
/** * 요청 포멧이 html 이 아닐 경우 redirect 하지 않고 데이터 형식으로 결과 출력 * * @param Request $request request * @return mixed */ public function prepare(Request $request) { if ($request->getRequestFormat() === 'json') { return new JsonResponse(array_merge($this->data, ['links' => ['rel' => 'self', 'href' => $this->targetUrl]])); } return parent::prepare($request); }
public function guessTemplateName(Request $request, $engine = 'twig') { if (!($namespace = $request->attributes->get('_controller'))) { throw new \InvalidArgumentException('Invalid Request Object'); } list($controller, $action) = explode('::', $namespace); if (!preg_match('/Controller\\\\(.+)Controller$/', $controller, $matchController)) { throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (it must be in a "Controller" sub-namespace and the class name must end with "Controller")', $controller)); } if (!preg_match('/^(.+)Action$/', $action, $matchAction)) { throw new \InvalidArgumentException(sprintf('The "%s" method does not look like an action method (it does not end with Action)', $action)); } if ($bundle = $this->getBundleForClass($controller)) { while ($bundleName = $bundle->getName()) { if (null === ($parentBundleName = $bundle->getParent())) { $bundleName = $bundle->getName(); break; } $bundles = $this->kernel->getBundle($parentBundleName, false); $bundle = array_pop($bundles); } } else { $bundleName = null; } return new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine); }
public function listAction(Request $request, $sort) { $format = $request->getRequestFormat(); if (!array_key_exists($sort, $this->sortFields)) { $msg = sprintf('%s is not a valid sorting field', $sort); if ('json' === $format) { return new JsonResponse(array('status' => 'error', 'message' => $msg), 406); } throw new HttpException($msg, 406); } $sortField = $this->sortFields[$sort]; $query = $this->getRepository('Developer')->queryAllWithBundlesSortedBy($sortField); $paginator = $this->getPaginator($query, $request->query->get('page', 1), $request->query->get('limit', 18)); if ('json' === $format) { $result = array('results' => array(), 'total' => $paginator->getNbResults()); /* @var $developer Developer */ foreach ($paginator as $developer) { $result['results'][] = array('name' => $developer->getName(), 'email' => $developer->getEmail(), 'avatarUrl' => $developer->getAvatarUrl(), 'fullName' => $developer->getFullName(), 'company' => $developer->getCompany(), 'location' => $developer->getLocation(), 'blog' => $developer->getUrl(), 'lastCommitAt' => $developer->getLastCommitAt() ? $developer->getLastCommitAt()->getTimestamp() : null, 'score' => $developer->getScore(), 'url' => $this->generateUrl('developer_show', array('name' => $developer->getName()), true)); } if ($paginator->hasPreviousPage()) { $result['prev'] = $this->generateUrl('developer_list', array('sort' => $sort, 'page' => $paginator->getPreviousPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true); } if ($paginator->hasNextPage()) { $result['next'] = $this->generateUrl('developer_list', array('sort' => $sort, 'page' => $paginator->getNextPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true); } return new JsonResponse($result); } $this->highlightMenu('developers'); return $this->render('KnpBundlesBundle:Developer:list.html.twig', array('developers' => $paginator, 'sort' => $sort, 'sortLegends' => $this->sortLegends)); }
/** * Returns response based on request content type * @param Request $request [description] * @param [type] $response_data [description] * @param integer $response_code [description] * @return [type] [description] */ protected function handleResponse(Request $request, $response_data, $response_code = 200) { $response = new Response(); $contentType = $request->headers->get('Content-Type'); $format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType); if ($format == 'json') { $serializer = $this->get('serializer'); $serialization_context = SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Default', 'detail', 'from_user', 'from_oauth')); $response->setContent($serializer->serialize($response_data, 'json', $serialization_context)); $response->headers->set('Content-Type', 'application/json'); } else { if (is_array($response_data)) { if (isset($response_data['message'])) { $response->setContent($response_data['message']); } else { $response->setContent(json_encode($response_data)); } } } if ($response_code == 0) { $response->setStatusCode(500); } else { $response->setStatusCode($response_code); } return $response; }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { $responseHeaders = $response->headers->all(); $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; } $attributes = array(); foreach ($request->attributes->all() as $key => $value) { if (is_object($value)) { $attributes[$key] = sprintf('Object(%s)', get_class($value)); if (is_callable(array($value, '__toString'))) { $attributes[$key] .= sprintf(' = %s', (string) $value); } } else { $attributes[$key] = $value; } } $content = null; try { $content = $request->getContent(); } catch (\LogicException $e) { // the user already got the request content as a resource $content = false; } $this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(), 'path_info' => $request->getPathInfo()); }
public function needConsoleInjection(Request $request, Response $response) { if ($request->isXmlHttpRequest() || !$response->headers->has('X-Debug-Token') || '3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat()) { return false; } return true; }
/** * Render the provided content. * * When using the publish workflow, enable the publish_workflow.request_listener * of the core bundle to have the contentDocument as well as the route * checked for being published. * We don't need an explicit check in this method. * * @param Request $request * @param object $contentDocument * @param string $contentTemplate Symfony path of the template to render * the content document. If omitted, the * default template is used. * * @return Response */ public function indexAction(Request $request, $contentDocument, $contentTemplate = null) { $contentTemplate = $contentTemplate ?: $this->defaultTemplate; $contentTemplate = str_replace(array('{_format}', '{_locale}'), array($request->getRequestFormat(), $request->getLocale()), $contentTemplate); $params = $this->getParams($request, $contentDocument); return $this->renderResponse($contentTemplate, $params); }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { $responseHeaders = $response->headers->all(); $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; } $attributes = array(); foreach ($request->attributes->all() as $key => $value) { $attributes[$key] = is_object($value) ? sprintf('Object(%s)', get_class($value)) : $value; } $this->data = array( 'format' => $request->getRequestFormat(), 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_attributes' => $request->hasSession() ? $request->getSession()->getAttributes() : array(), ); }
/** * Creates a Response object to send upon a successful logout. * * @param Request $request * * @return Response never null */ public function onLogoutSuccess(Request $request) { if ($request->isXmlHttpRequest() or 'json' == $request->getRequestFormat()) { return new JsonResponse(true); } return new RedirectResponse($this->router->generate('homepage')); }
/** * {@inheritdoc} */ public function filter(RouteCollection $collection, Request $request) { // Generates a list of Symfony formats matching the acceptable MIME types. // @todo replace by proper content negotiation library. $acceptable_mime_types = $request->getAcceptableContentTypes(); $acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types)); $primary_format = $request->getRequestFormat(); foreach ($collection as $name => $route) { // _format could be a |-delimited list of supported formats. $supported_formats = array_filter(explode('|', $route->getRequirement('_format'))); if (empty($supported_formats)) { // No format restriction on the route, so it always matches. Move it to // the end of the collection by re-adding it. $collection->add($name, $route); } elseif (in_array($primary_format, $supported_formats)) { // Perfect match, which will get a higher priority by leaving the route // on top of the list. } elseif (in_array('*/*', $acceptable_mime_types) || array_intersect($acceptable_formats, $supported_formats)) { // Move it to the end of the list. $collection->add($name, $route); } else { // Remove the route if it does not match at all. $collection->remove($name); } } if (count($collection)) { return $collection; } // We do not throw a // \Symfony\Component\Routing\Exception\ResourceNotFoundException here // because we don't want to return a 404 status code, but rather a 406. throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types)))); }
public function getAll(Request $request) { $data = ['success' => false, 'message' => '', 'result' => null]; try { $repository = $this->getUsrListRepository(); $lists = $repository->findUserLists($this->getAuthenticatedUser()); $result = []; foreach ($lists as $list) { $owners = $entries = []; foreach ($list->getOwners() as $owner) { $user = $owner->getUser(); $owners[] = ['usr_id' => $user->getId(), 'display_name' => $user->getDisplayName(), 'position' => $user->getActivity(), 'job' => $user->getJob(), 'company' => $user->getCompany(), 'email' => $user->getEmail(), 'role' => $owner->getRole()]; } foreach ($list->getEntries() as $entry) { $user = $entry->getUser(); $entries[] = ['usr_id' => $user->getId(), 'display_name' => $user->getDisplayName(), 'position' => $user->getActivity(), 'job' => $user->getJob(), 'company' => $user->getCompany(), 'email' => $user->getEmail()]; } $result[] = ['name' => $list->getName(), 'created' => $list->getCreated()->format(DATE_ATOM), 'updated' => $list->getUpdated()->format(DATE_ATOM), 'owners' => $owners, 'users' => $entries]; } $data = ['success' => true, 'message' => '', 'result' => $result]; } catch (ControllerException $e) { $lists = []; $data = ['success' => false, 'message' => $e->getMessage()]; } catch (\Exception $e) { $lists = []; } if ($request->getRequestFormat() == 'json') { return $this->app->json($data); } return $this->render('prod/actions/Feedback/lists-all.html.twig', ['lists' => $lists]); }
public function prepare(Request $request) { if ('xml' === $request->getRequestFormat()) { $this->requestFormat = 'xml'; $this->headers->set('Content-Type', 'application/hal+xml'); } return parent::prepare($request); }
/** * @Route( "/ueditor/{text}",name="hyperbolaa_ueditor",requirements={"text" = ".+" }) * @Method("GET") * @param Request $request The Request object * @param string $text The text to be converted to a QRCode image * @return Response The response with the image */ public function ueditorAction(Request $request, $text = '') { $format = $request->getRequestFormat(); $ueditorService = $this->get('hyperbolaa_ueditor'); $name = $ueditorService->getName(); $response = new Response($name); return $response; }
/** * @param ApiResponse $apiResponse to convert to a Symfony Response. * @param Request $request that needs this Response. * * @return Response */ public function toSymfonyResponse(ApiResponse $apiResponse, Request $request) { $format = $request->getRequestFormat($this->defaultResponseFormat); $serialized = $this->serializer->serialize($apiResponse->getData(), $format); $response = new Response($serialized, $apiResponse->getStatusCode(), $apiResponse->getHeaders()); $response->headers->set('Content-Type', $request->getMimeType($format)); return $response; }
/** * {@inheritDoc} */ public function onAuthenticationFailure(Request $request, AuthenticationException $exception) { if ($request->isXmlHttpRequest() || $request->getRequestFormat() !== 'html') { $json = array('code' => 401, 'message' => $this->translator->trans($exception->getMessage())); return new Response(json_encode($json), 401); } return parent::onAuthenticationFailure($request, $exception); }
/** * Processes a request that will vary with Accept header. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return mixed */ public function content(Request $request) { if ($request->getRequestFormat() === 'json') { return new CacheableJsonResponse(['content' => 'oh hai this is json']); } else { return new CacheableResponse("<p>oh hai this is html.</p>"); } }
/** * Processes a request that will vary with Accept header. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return mixed */ public function content(Request $request) { if ($request->getRequestFormat() === 'json') { return new JsonResponse(array('content' => 'oh hai this is json')); } else { return new Response("<p>oh hai this is html.</p>"); } }
/** * {@inheritDoc} */ public function onAuthenticationSuccess(Request $request, TokenInterface $token) { if ($request->isXmlHttpRequest() || $request->getRequestFormat() !== 'html') { $json = array('username' => $token->getUsername(), 'redirectUrl' => $this->determineTargetUrl($request)); return new Response(json_encode($json)); } return parent::onAuthenticationSuccess($request, $token); }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { $responseHeaders = $response->headers->all(); $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; } $attributes = array(); foreach ($request->attributes->all() as $key => $value) { if ('_route' == $key && is_object($value)) { $value = $value->getPattern(); } $attributes[$key] = $this->varToString($value); } $content = null; try { $content = $request->getContent(); } catch (\LogicException $e) { // the user already got the request content as a resource $content = false; } $sessionMetadata = array(); $sessionAttributes = array(); $flashes = array(); if ($request->hasSession()) { $session = $request->getSession(); if ($session->isStarted()) { $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated()); $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed()); $sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime(); $sessionAttributes = $session->all(); $flashes = $session->getFlashBag()->peekAll(); } } $this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', 'locale' => $request->getLocale()); if (isset($this->controllers[$request])) { $controller = $this->controllers[$request]; if (is_array($controller)) { try { $r = new \ReflectionMethod($controller[0], $controller[1]); $this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getStartLine()); } catch (\ReflectionException $re) { if (is_callable($controller)) { // using __call or __callStatic $this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => 'n/a', 'line' => 'n/a'); } } } elseif ($controller instanceof \Closure) { $this->data['controller'] = 'Closure'; } else { $this->data['controller'] = (string) $controller ?: 'n/a'; } unset($this->controllers[$request]); } }
/** * @param Request $request */ protected function setRequestFormat(Request $request) { $default = Format::getDefault(); $format = $request->getRequestFormat($request->query->get('_format', $default)); if (!in_array($format, $this->outputFormats)) { $format = $default; } $request->setRequestFormat($format); }
/** * Generates a proxy URI for a given controller. * * @param ControllerReference $reference A ControllerReference instance * @param Request $request A Request instance * * @return string A proxy URI */ protected function generateProxyUri(ControllerReference $reference, Request $request) { if (!isset($reference->attributes['_format'])) { $reference->attributes['_format'] = $request->getRequestFormat(); } $reference->attributes['_controller'] = $reference->controller; $reference->query['_path'] = http_build_query($reference->attributes, '', '&'); return $request->getUriForPath($this->proxyPath . '?' . http_build_query($reference->query, '', '&')); }
public function recentArticlesAction($max = 3, Request $request) { // make a database call or other logic // to get the "$max" most recent articles $articles = $this->getMostRecentArticles($max); dump($articles); $format = $request->getRequestFormat(); return $this->render('article/recent_list.' . $format . '.twig', array('articles' => $articles)); }
/** * @param string $_action * @param Request $request * @return mixed * @throws NotFoundHttpException */ public function callAction(string $_action, Request $request) { $event = new ActionEvent($this, $request); $action = $this->getAction($_action); if ($action === null) { throw new NotFoundHttpException('Action "' . $_action . '" does not exist'); } return $action->call($event, $request->getRequestFormat()); }
/** * Get the error format and its associated MIME type. * * @param Request $request * @param array $errorFormats * * @return array */ public static function guessErrorFormat(Request $request, array $errorFormats) : array { $requestFormat = $request->getRequestFormat(null); if (null !== $requestFormat && isset($errorFormats[$requestFormat])) { return ['key' => $requestFormat, 'value' => $errorFormats[$requestFormat]]; } reset($errorFormats); return each($errorFormats); }