本文整理汇总了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);
}
示例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);
}
示例3: testSplitHttpAcceptHeader
/**
* @dataProvider splitHttpAcceptHeaderData
*/
public function testSplitHttpAcceptHeader($acceptHeader, $expected)
{
$request = new Request();
$this->assertEquals($expected, $request->splitHttpAcceptHeader($acceptHeader));
}
示例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();
}