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


PHP Request::splitHttpAcceptHeader方法代码示例

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


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

示例1: getBestFormat

 /**
  * Detect the request format based on the priorities and the Accept header
  *
  * Note: Request "_format" parameter is considered the preferred Accept header
  *
  * @param   Request     $request          The request
  * @param   array       $priorities       Ordered array of formats (highest priority first)
  * @param   Boolean     $preferExtension  If to consider the extension last or first
  *
  * @return  void|string                 The format string
  */
 public function getBestFormat(Request $request, array $priorities, $preferExtension = false)
 {
     $mimetypes = $request->splitHttpAcceptHeader($request->headers->get('Accept'));
     $extension = $request->get('_format');
     if (null !== $extension && $request->getMimeType($extension)) {
         $mimetypes[$request->getMimeType($extension)] = $preferExtension ? reset($mimetypes) + 1 : end($mimetypes) - 1;
         arsort($mimetypes);
     }
     if (empty($mimetypes)) {
         return null;
     }
     $catchAllEnabled = in_array('*/*', $priorities);
     return $this->getFormatByPriorities($request, $mimetypes, $priorities, $catchAllEnabled);
 }
开发者ID:hykz,项目名称:Depot,代码行数:25,代码来源:FormatNegotiator.php

示例2: getBestFormat

 /**
  * Detect the request format based on the priorities and the Accept header
  *
  * Note: Request "_format" parameter is considered the preferred Accept header
  *
  * @param   Request     $request          The request
  * @param   array       $priorities       Ordered array of formats (highest priority first)
  * @param   Boolean     $preferExtension  If to consider the extension last or first
  *
  * @return  void|string                 The format string
  */
 public function getBestFormat(Request $request, array $priorities, $preferExtension = false)
 {
     // BC - Maintain this while 2.0 and 2.1 dont reach their end of life
     // Note: Request::splitHttpAcceptHeader is deprecated since version 2.2, to be removed in 2.3.
     if (class_exists('Symfony\\Component\\HttpFoundation\\AcceptHeader')) {
         $mimetypes = array();
         foreach (AcceptHeader::fromString($request->headers->get('Accept'))->all() as $item) {
             $mimetypes[$item->getValue()] = $item->getQuality();
         }
     } else {
         $mimetypes = $request->splitHttpAcceptHeader($request->headers->get('Accept'));
     }
     $extension = $request->get('_format');
     if (null !== $extension && $request->getMimeType($extension)) {
         $mimetypes[$request->getMimeType($extension)] = $preferExtension ? reset($mimetypes) + 1 : end($mimetypes) - 1;
         arsort($mimetypes);
     }
     if (empty($mimetypes)) {
         return null;
     }
     $catchAllEnabled = in_array('*/*', $priorities);
     return $this->getFormatByPriorities($request, $mimetypes, $priorities, $catchAllEnabled);
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:34,代码来源:FormatNegotiator.php

示例3: testSplitHttpAcceptHeader

 /**
  * @dataProvider splitHttpAcceptHeaderData
  */
 public function testSplitHttpAcceptHeader($acceptHeader, $expected)
 {
     $request = new Request();
     $this->assertEquals($expected, $request->splitHttpAcceptHeader($acceptHeader));
 }
开发者ID:vieiragabriel,项目名称:moodle-block_gchat,代码行数:8,代码来源:RequestTest.php

示例4: testSplitHttpAcceptHeader

 /**
  * @dataProvider splitHttpAcceptHeaderData
  */
 public function testSplitHttpAcceptHeader($acceptHeader, $expected)
 {
     $request = new Request();
     set_error_handler(array($this, "deprecationErrorHandler"));
     $this->assertEquals($expected, $request->splitHttpAcceptHeader($acceptHeader));
     restore_error_handler();
 }
开发者ID:rodionrakib,项目名称:twig,代码行数:10,代码来源:RequestTest.php


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