本文整理汇总了PHP中Sabre\HTTP\Util::negotiate方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::negotiate方法的具体用法?PHP Util::negotiate怎么用?PHP Util::negotiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\HTTP\Util
的用法示例。
在下文中一共展示了Util::negotiate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: httpAfterGet
/**
* This event is triggered after GET requests.
*
* This is used to transform data into jCal, if this was requested.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return void
*/
function httpAfterGet(RequestInterface $request, ResponseInterface $response)
{
if (strpos($response->getHeader('Content-Type'), 'text/calendar') === false) {
return;
}
$result = HTTP\Util::negotiate($request->getHeader('Accept'), ['text/calendar', 'application/calendar+json']);
if ($result !== 'application/calendar+json') {
// Do nothing
return;
}
// Transforming.
$vobj = VObject\Reader::read($response->getBody());
$jsonBody = json_encode($vobj->jsonSerialize());
$response->setBody($jsonBody);
$response->setHeader('Content-Type', 'application/calendar+json');
$response->setHeader('Content-Length', strlen($jsonBody));
}
示例2: negotiateVCard
/**
* This helper function performs the content-type negotiation for vcards.
*
* It will return one of the following strings:
* 1. vcard3
* 2. vcard4
* 3. jcard
*
* It defaults to vcard3.
*
* @param string $input
* @param string $mimeType
* @return string
*/
protected function negotiateVCard($input, &$mimeType = null)
{
$result = HTTP\Util::negotiate($input, ['text/x-vcard', 'text/vcard', 'text/vcard; version=4.0', 'text/vcard; version=3.0', 'application/vcard+json']);
$mimeType = $result;
switch ($result) {
default:
case 'text/x-vcard':
case 'text/vcard':
case 'text/vcard; version=3.0':
$mimeType = 'text/vcard';
return 'vcard3';
case 'text/vcard; version=4.0':
return 'vcard4';
case 'application/vcard+json':
return 'jcard';
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
}
示例3: negotiateVCard
/**
* This helper function performs the content-type negotiation for vcards.
*
* It will return one of the following strings:
* 1. vcard3
* 2. vcard4
* 3. jcard
*
* It defaults to vcard3.
*
* @param string $input
* @param string $mimeType
* @return string
*/
protected function negotiateVCard($input, &$mimeType = null) {
$result = HTTP\Util::negotiate(
$input,
[
// Most often used mime-type. Version 3
'text/x-vcard',
// The correct standard mime-type. Defaults to version 3 as
// well.
'text/vcard',
// vCard 4
'text/vcard; version=4.0',
// vCard 3
'text/vcard; version=3.0',
// jCard
'application/vcard+json',
]
);
$mimeType = $result;
switch ($result) {
default :
case 'text/x-vcard' :
case 'text/vcard' :
case 'text/vcard; version=3.0' :
$mimeType = 'text/vcard';
return 'vcard3';
case 'text/vcard; version=4.0' :
return 'vcard4';
case 'application/vcard+json' :
return 'jcard';
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
}