当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setRequestFormat方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::setRequestFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setRequestFormat方法的具体用法?PHP Request::setRequestFormat怎么用?PHP Request::setRequestFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::setRequestFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     if ($request->headers->has('Accept')) {
         $request->setRequestFormat($request->getFormat($request->headers->get('Accept')));
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
开发者ID:Jbartsch,项目名称:travelbruh-api,代码行数:10,代码来源:FormatSetter.php

示例2: findTemplate

 /**
  * Just a modified Symfony\Bundle\TwigBundle\Controller\ExceptionController::findTemplate().
  * It will try to find an appropriate error template in the CoreBundle and will fallback to
  * the Twig default template if it can't find anything.
  *
  * @param Request $request
  * @param string  $format
  * @param int     $code          An HTTP response status code
  * @param bool    $showException
  *
  * @return string
  */
 protected function findTemplate(Request $request, $format, $code, $showException)
 {
     $name = $showException ? 'exception' : 'error';
     if ($showException && 'html' == $format) {
         $name = 'exception_full';
     }
     // For error pages, try to find a template for the specific HTTP status code and format
     if (!$showException) {
         // CampaignChain template?
         $template = sprintf('@CampaignChainCore/Exception/%s%s.%s.twig', $name, $code, $format);
         if ($this->templateExists($template)) {
             return $template;
         }
         // Fallback to default
         $template = sprintf('@Twig/Exception/%s%s.%s.twig', $name, $code, $format);
         if ($this->templateExists($template)) {
             return $template;
         }
     }
     // try to find a template for the given format
     // CampaignChain template?
     $template = sprintf('@CampaignChainCore/Exception/%s.%s.twig', $name, $code, $format);
     if ($this->templateExists($template)) {
         return $template;
     }
     // Fallback to default
     $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format);
     if ($this->templateExists($template)) {
         return $template;
     }
     // default to a generic HTML exception
     $request->setRequestFormat('html');
     return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
 }
开发者ID:CampaignChain,项目名称:core,代码行数:46,代码来源:ExceptionController.php

示例3: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     foreach ($this->formats as $format => $mime_type) {
         $request->setFormat($format, $mime_type);
     }
     $request->setRequestFormat($this->negotiator->getContentType($request));
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:11,代码来源:NegotiationMiddleware.php

示例4: it_sets_content_type_header_depending_on_request_format

 /** @test */
 public function it_sets_content_type_header_depending_on_request_format()
 {
     $response = $this->provideResponse();
     $request = new Request();
     $request->setRequestFormat('xml');
     $response->prepare($request);
     $this->assertSame('application/hal+xml', $response->headers->get('Content-Type'));
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:9,代码来源:HalResponseTest.php

示例5: testFallbackWhenNotSupported

 public function testFallbackWhenNotSupported()
 {
     $request = new Request();
     $request->setRequestFormat('html');
     $format = ErrorFormatGuesser::guessErrorFormat($request, ['xml' => ['text/xml'], 'jsonld' => ['application/ld+json', 'application/json']]);
     $this->assertEquals('xml', $format['key']);
     $this->assertEquals('text/xml', $format['value'][0]);
 }
开发者ID:api-platform,项目名称:core,代码行数:8,代码来源:ErrorFormatGuesserTest.php

示例6: setRequestFormat

 /**
  * @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);
 }
开发者ID:dhaarbrink,项目名称:SymfonyRestApiBundle,代码行数:12,代码来源:RequestTransformer.php

示例7: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     $mapping = ['application/json' => 'json', 'application/hal+json' => 'hal_json', 'application/xml' => 'xml', 'text/html' => 'html'];
     $accept = $request->headers->get('Accept') ?: ['text/html'];
     if (isset($mapping[$accept[0]])) {
         $request->setRequestFormat($mapping[$accept[0]]);
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:AcceptHeaderMiddleware.php

示例8: definitionAction

 /**
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function definitionAction(Request $request, $webservice)
 {
     $response = new Response($this->getWebServiceContext($webservice)->getWsdlFileContent($this->container->get('router')->generate('_webservice_call', array('webservice' => $webservice), UrlGeneratorInterface::ABSOLUTE_URL)));
     $query = $request->query;
     if ($query->has('wsdl') || $query->has('WSDL')) {
         $request->setRequestFormat('wsdl');
     }
     return $response;
 }
开发者ID:cybermo,项目名称:BeSimpleSoap,代码行数:12,代码来源:SoapWebServiceController.php

示例9: testDoNothingWhenHtmlRequested

 public function testDoNothingWhenHtmlRequested()
 {
     $request = new Request([], [], ['_api_respond' => true]);
     $request->setRequestFormat('html');
     $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class);
     $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
     $listener = new ExceptionListener('foo:bar');
     $listener->onKernelException($eventProphecy->reveal());
 }
开发者ID:api-platform,项目名称:core,代码行数:9,代码来源:ExceptionListenerTest.php

示例10: __invoke

 public function __invoke(Request $request, FlattenException $exception, $format)
 {
     $statusCode = $exception->getStatusCode();
     try {
         $template = $this->twig->resolveTemplate(['Exception/error' . $statusCode . '.' . $format . '.twig', 'Exception/error.' . $format . '.twig', 'Exception/error.html.twig']);
     } catch (\Twig_Error_Loader $e) {
         $request->setRequestFormat('html');
         $content = (new ExceptionHandler(false))->getHtml($exception);
         return new Response($content, $exception->getStatusCode(), $exception->getHeaders());
     }
     // We cannot find a template that matches the precise format so we will default
     // to html as previously in the ExceptionHandler
     if (substr($template->getTemplateName(), -9) == 'html.twig') {
         $request->setRequestFormat('html');
     }
     $variables = ['exception' => $exception, 'status_code' => $statusCode, 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : ''];
     return new Response($template->render($variables), $statusCode);
 }
开发者ID:flint,项目名称:brick,代码行数:18,代码来源:ExceptionController.php

示例11: getParameters

 public function getParameters()
 {
     $respondRequest = new Request([], [], ['_api_respond' => true]);
     $respondRequest->setRequestFormat('html');
     $resourceClassRequest = new Request([], [], ['_api_resource_class' => 'Foo']);
     $resourceClassRequest->setRequestFormat('html');
     $jsonRequest = new Request([], [], ['_api_resource_class' => 'Foo']);
     $jsonRequest->setRequestFormat('json');
     return [[$respondRequest, 'api_platform.swagger.action.ui'], [$resourceClassRequest, 'api_platform.swagger.action.ui'], [new Request(), null], [$jsonRequest, null]];
 }
开发者ID:api-platform,项目名称:core,代码行数:10,代码来源:SwaggerUiListenerTest.php

示例12: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     // Register available mime types.
     foreach ($this->formats as $format => $mime_type) {
         $request->setFormat($format, $mime_type);
     }
     // Determine the request format using the negotiator.
     $request->setRequestFormat($this->getContentType($request));
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:NegotiationMiddleware.php

示例13: handle

 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
         $data = json_decode($request->getContent(), true);
         $request->request->replace(is_array($data) ? $data : []);
     }
     if (in_array('application/json', $request->getAcceptableContentTypes())) {
         $request->setRequestFormat('json');
     }
     return $response = $this->app->handle($request, $type, $catch);
 }
开发者ID:tuimedia,项目名称:forum,代码行数:11,代码来源:JsonRequestKernel.php

示例14: showAction

 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     // IF an API URL, show the result as JSON - otherwise show HTML format
     $format = strncmp($request->getPathInfo(), '/api/', strlen('/api/')) == 0 ? 'json' : 'html';
     $request->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
开发者ID:johnprice99,项目名称:predictions,代码行数:11,代码来源:ExceptionController.php

示例15: testOnKernelControllerNegotiationStopped

 public function testOnKernelControllerNegotiationStopped()
 {
     $event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock();
     $request = new Request();
     $request->setRequestFormat('xml');
     $event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
     $formatNegotiator = new FormatNegotiator();
     $formatNegotiator->add(new RequestMatcher('/'), array('stop' => true));
     $formatNegotiator->add(new RequestMatcher('/'), array('fallback_format' => 'json'));
     $listener = new FormatListener($formatNegotiator);
     $listener->onKernelRequest($event);
     $this->assertEquals($request->getRequestFormat(), 'xml');
 }
开发者ID:ericshaffer,项目名称:FOSRestBundle,代码行数:13,代码来源:FormatListenerTest.php


注:本文中的Symfony\Component\HttpFoundation\Request::setRequestFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。