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


PHP Request::getMimeTypes方法代码示例

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


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

示例1: extendRequestFormats

 private static function extendRequestFormats(Request $request, array $formats)
 {
     foreach ($formats as $format => $mimeTypes) {
         if (method_exists(get_class($request), 'getMimeTypes')) {
             $mimeTypes = array_merge($mimeTypes, Request::getMimeTypes($format));
         } elseif (null !== $request->getMimeType($format)) {
             $class = new \ReflectionClass(get_class($request));
             $properties = $class->getStaticProperties();
             if (isset($properties['formats'][$format])) {
                 $mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
             }
         }
         $request->setFormat($format, array_unique($mimeTypes));
     }
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:15,代码来源:RequestFormatNegotiator.php

示例2: onKernelRequest

 /**
  * Core request handler.
  *
  * @param GetResponseEvent $event The event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
         return;
     }
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         foreach ($this->mimeTypes as $format => $mimeTypes) {
             if (method_exists(Request::class, 'getMimeTypes')) {
                 $mimeTypes = array_merge($mimeTypes, Request::getMimeTypes($format));
             } elseif (null !== $request->getMimeType($format)) {
                 $class = new \ReflectionClass(Request::class);
                 $properties = $class->getStaticProperties();
                 $mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
             }
             $request->setFormat($format, $mimeTypes);
         }
     }
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:24,代码来源:MimeTypeListener.php

示例3: onKernelRequest

 /**
  * Sets the applicable format to the HttpFoundation Request.
  *
  * @param GetResponseEvent $event
  *
  * @throws NotFoundHttpException
  * @throws NotAcceptableHttpException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->has('_api_resource_class') && !$request->attributes->has('_api_respond')) {
         return;
     }
     $this->populateMimeTypes();
     $this->addRequestFormats($request, $this->formats);
     // Empty strings must be converted to null because the Symfony router doesn't support parameter typing before 3.2 (_format)
     if (null === ($routeFormat = $request->attributes->get('_format') ?: null)) {
         $mimeTypes = array_keys($this->mimeTypes);
     } elseif (!isset($this->formats[$routeFormat])) {
         throw new NotFoundHttpException('Not Found');
     } else {
         $mimeTypes = Request::getMimeTypes($routeFormat);
     }
     // First, try to guess the format from the Accept header
     $accept = $request->headers->get('Accept');
     if (null !== $accept) {
         if (null === ($acceptHeader = $this->negotiator->getBest($accept, $mimeTypes))) {
             throw $this->getNotAcceptableHttpException($accept, $mimeTypes);
         }
         $request->setRequestFormat($request->getFormat($acceptHeader->getType()));
         return;
     }
     // Then use the Symfony request format if available and applicable
     $requestFormat = $request->getRequestFormat(null) ?: null;
     if (null !== $requestFormat) {
         $mimeType = $request->getMimeType($requestFormat);
         if (isset($this->mimeTypes[$mimeType])) {
             return;
         }
         throw $this->getNotAcceptableHttpException($mimeType);
     }
     // Finally, if no Accept header nor Symfony request format is set, return the default format
     reset($this->formats);
     $request->setRequestFormat(each($this->formats)['key']);
 }
开发者ID:api-platform,项目名称:core,代码行数:46,代码来源:AddFormatListener.php

示例4: testGetMimeTypesFromInexistentFormat

 public function testGetMimeTypesFromInexistentFormat()
 {
     $request = new Request();
     $this->assertNull($request->getMimeType('foo'));
     $this->assertEquals(array(), Request::getMimeTypes('foo'));
 }
开发者ID:symfony,项目名称:symfony,代码行数:6,代码来源:RequestTest.php

示例5: normalizePriorities

 /**
  * Transform the format (json, html, ...) to their mimeType form (application/json, text/html, ...).
  *
  * @param Request  $request
  * @param string[] $priorities
  *
  * @return string[] formatted priorities
  */
 private function normalizePriorities(Request $request, array $priorities)
 {
     $priorities = $this->sanitize($priorities);
     $mimeTypes = array();
     foreach ($priorities as $priority) {
         if (strpos($priority, '/')) {
             $mimeTypes[] = $priority;
             continue;
         }
         if (method_exists(Request::class, 'getMimeTypes')) {
             $mimeTypes = array_merge($mimeTypes, Request::getMimeTypes($priority));
         } elseif (null !== $request->getMimeType($priority)) {
             $class = new \ReflectionClass(Request::class);
             $properties = $class->getStaticProperties();
             $mimeTypes = array_merge($mimeTypes, $properties['formats'][$priority]);
         }
         if (isset($this->mimeTypes[$priority])) {
             foreach ($this->mimeTypes[$priority] as $mimeType) {
                 $mimeTypes[] = $mimeType;
             }
         }
     }
     return $mimeTypes;
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:32,代码来源:FormatNegotiator.php


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