本文整理汇总了PHP中Sabre\HTTP\RequestInterface::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeaders方法的具体用法?PHP RequestInterface::getHeaders怎么用?PHP RequestInterface::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\HTTP\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createCurlSettingsArray
/**
* Turns a RequestInterface object into an array with settings that can be
* fed to curl_setopt
*
* @param RequestInterface $request
* @return array
*/
protected function createCurlSettingsArray(RequestInterface $request)
{
$settings = $this->curlSettings;
switch ($request->getMethod()) {
case 'HEAD':
$settings[CURLOPT_NOBODY] = true;
$settings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
$settings[CURLOPT_POSTFIELDS] = '';
$settings[CURLOPT_PUT] = false;
break;
case 'GET':
$settings[CURLOPT_CUSTOMREQUEST] = 'GET';
$settings[CURLOPT_POSTFIELDS] = '';
$settings[CURLOPT_PUT] = false;
break;
default:
$body = $request->getBody();
if (is_resource($body)) {
// This needs to be set to PUT, regardless of the actual
// method used. Without it, INFILE will be ignored for some
// reason.
$settings[CURLOPT_PUT] = true;
$settings[CURLOPT_INFILE] = $request->getBody();
} else {
// For security we cast this to a string. If somehow an array could
// be passed here, it would be possible for an attacker to use @ to
// post local files.
$settings[CURLOPT_POSTFIELDS] = (string) $body;
}
$settings[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
break;
}
$nHeaders = [];
foreach ($request->getHeaders() as $key => $values) {
foreach ($values as $value) {
$nHeaders[] = $key . ': ' . $value;
}
}
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
$settings[CURLOPT_URL] = $request->getUrl();
// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_PROTOCOLS')) {
$settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// FIXME: CURLOPT_REDIR_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
$settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
return $settings;
}