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


PHP RequestInterface::getHeaders方法代码示例

本文整理汇总了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;
 }
开发者ID:samj1912,项目名称:repo,代码行数:57,代码来源:Client.php


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