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


PHP RequestInterface::getScheme方法代码示例

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


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

示例1: addCookies

 /**
  * Add cookies to a request based on the destination of the request and
  * the cookies stored in the storage backend.  Any previously set cookies
  * will be removed.
  *
  * @param RequestInterface $request Request to add cookies to.  If the
  *      request object already has a cookie header, then no further cookies
  *      will be added.
  *
  * @return array Returns an array of the cookies that were added
  */
 public function addCookies(RequestInterface $request)
 {
     $request->removeHeader('Cookie');
     // Find cookies that match this request
     $cookies = $this->jar->getCookies($request->getHost(), $request->getPath());
     $match = false;
     if ($cookies) {
         foreach ($cookies as $cookie) {
             $match = true;
             // If a port restriction is set, validate the port
             if (!empty($cookie['port'])) {
                 if (!in_array($request->getPort(), $cookie['port'])) {
                     $match = false;
                 }
             }
             // Validate the secure flag
             if ($cookie['secure']) {
                 if ($request->getScheme() != 'https') {
                     $match = false;
                 }
             }
             // If this request is eligible for the cookie, then merge it in
             if ($match) {
                 $request->addCookie($cookie['cookie'][0], isset($cookie['cookie'][1]) ? $cookie['cookie'][1] : null);
             }
         }
     }
     return $match && $cookies ? $cookies : array();
 }
开发者ID:norv,项目名称:guzzle,代码行数:40,代码来源:CookiePlugin.php

示例2: getCacheKey

 /**
  * Calculate the hash key of a request object
  *
  * @param RequestInterface $request Request to hash
  * @param string           $raw     Set to TRUE to retrieve the un-encoded string for debugging
  *
  * @return string
  */
 public function getCacheKey(RequestInterface $request, $raw = false)
 {
     // See if the key has already been calculated
     $key = $request->getParams()->get('cache.key');
     // Always recalculate when using the raw option
     if (!$key || $raw) {
         // Generate the start of the key
         $key = $request->getMethod() . '_' . $request->getScheme() . '_' . $request->getHost() . $request->getPath();
         $filterHeaders = array('Cache-Control');
         $filterQuery = array();
         // Check to see how and if the key should be filtered
         foreach (explode(';', $request->getParams()->get('cache.key_filter')) as $part) {
             $pieces = array_map('trim', explode('=', $part));
             if (isset($pieces[1])) {
                 $remove = array_map('trim', explode(',', $pieces[1]));
                 if ($pieces[0] == 'header') {
                     $filterHeaders = array_merge($filterHeaders, $remove);
                 } elseif ($pieces[0] == 'query') {
                     $filterQuery = array_merge($filterQuery, $remove);
                 }
             }
         }
         // Use the filtered query string
         $queryString = (string) $request->getQuery()->filter(function ($key, $value) use($filterQuery) {
             return !in_array($key, $filterQuery);
         });
         // Use the filtered headers
         $headerString = http_build_query($request->getHeaders()->map(function ($key, $value) {
             return count($value) == 1 ? $value[0] : $value;
         })->filter(function ($key, $value) use($filterHeaders) {
             return !in_array($key, $filterHeaders);
         })->getAll());
         if ($raw) {
             $key = strtolower('gz_' . $key . $queryString . '_' . $headerString);
         } else {
             $key = strtolower('gz_' . md5($key . $queryString . '_' . $headerString));
             $request->getParams()->set('cache.key', $key);
         }
     }
     return $key;
 }
开发者ID:vieiragabriel,项目名称:moodle-block_gchat,代码行数:49,代码来源:CachePlugin.php

示例3: getMatchingCookies

 /**
  * {@inheritdoc}
  */
 public function getMatchingCookies(RequestInterface $request)
 {
     // Find cookies that match this request
     $cookies = $this->all($request->getHost(), $request->getPath());
     // Remove ineligible cookies
     foreach ($cookies as $index => $cookie) {
         if (!$cookie->matchesPort($request->getPort()) || $cookie->getSecure() && $request->getScheme() != 'https') {
             unset($cookies[$index]);
         }
     }
     return $cookies;
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:15,代码来源:ArrayCookieJar.php

示例4: collectRequest

 /**
  * Collect & sanitize data about a Guzzle request
  *
  * @param Guzzle\Http\Message\RequestInterface $request
  *
  * @return array
  */
 private function collectRequest(GuzzleRequestInterface $request)
 {
     $body = null;
     if ($request instanceof EntityEnclosingRequestInterface) {
         $body = (string) $request->getBody();
     }
     return array('headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'path' => $request->getPath(), 'query' => $request->getQuery(), 'body' => $body);
 }
开发者ID:ma-si,项目名称:GuzzleBundle,代码行数:15,代码来源:GuzzleDataCollector.php

示例5: exec

 private function exec(\Guzzle\Http\Message\RequestInterface $request)
 {
     $start = microtime(true);
     $this->responseCode = 0;
     // Get snapshot of request headers.
     $request_headers = $request->getRawHeaders();
     // Mask authorization for logs.
     $request_headers = preg_replace('!\\nAuthorization: (Basic|Digest) [^\\r\\n]+\\r!i', "\nAuthorization: \$1 [**masked**]\r", $request_headers);
     try {
         $response = $request->send();
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     } catch (\Guzzle\Http\Exception\CurlException $e) {
         // Timeouts etc.
         DebugData::$raw = '';
         DebugData::$code = $e->getErrorNo();
         DebugData::$code_status = $e->getError();
         DebugData::$code_class = 0;
         DebugData::$exception = $e->getMessage();
         DebugData::$opts = array('request_headers' => $request_headers);
         DebugData::$data = null;
         $exception = new ResponseException($e->getError(), $e->getErrorNo(), $request->getUrl(), DebugData::$opts);
         $exception->requestObj = $request;
         // Log Exception
         $headers_array = $request->getHeaders();
         unset($headers_array['Authorization']);
         $headerString = '';
         foreach ($headers_array as $value) {
             $headerString .= $value->getName() . ': ' . $value . " ";
         }
         $log_message = '{code_status} ({code}) Request Details:[ {r_method} {r_resource} {r_scheme} {r_headers} ]';
         $httpScheme = strtoupper(str_replace('https', 'http', $request->getScheme())) . $request->getProtocolVersion();
         $log_params = array('code' => $e->getErrorNo(), 'code_status' => $e->getError(), 'r_method' => $request->getUrl(), 'r_resource' => $request->getRawHeaders(), 'r_scheme' => $httpScheme, 'r_headers' => $headerString);
         self::$logger->emergency($log_message, $log_params);
         throw $exception;
     }
     $this->responseCode = $response->getStatusCode();
     $this->responseText = trim($response->getBody(true));
     $this->responseLength = $response->getContentLength();
     $this->responseMimeType = $response->getContentType();
     $this->responseObj = array();
     $content_type = $response->getContentType();
     $firstChar = substr($this->responseText, 0, 1);
     if (strpos($content_type, '/json') !== false && ($firstChar == '{' || $firstChar == '[')) {
         $response_obj = @json_decode($this->responseText, true);
         if (is_array($response_obj)) {
             $this->responseObj = $response_obj;
         }
     }
     $status = self::getStatusMessage($this->responseCode);
     $code_class = floor($this->responseCode / 100);
     DebugData::$raw = $this->responseText;
     DebugData::$opts = array('request_headers' => $request_headers, 'response_headers' => $response->getRawHeaders());
     if ($request instanceof \Guzzle\Http\Message\EntityEnclosingRequestInterface) {
         DebugData::$opts['request_body'] = (string) $request->getBody();
     }
     DebugData::$opts['request_type'] = class_implements($request);
     DebugData::$data = $this->responseObj;
     DebugData::$code = $this->responseCode;
     DebugData::$code_status = $status;
     DebugData::$code_class = $code_class;
     DebugData::$exception = null;
     DebugData::$time_elapsed = microtime(true) - $start;
     if ($code_class != 2) {
         $uri = $request->getUrl();
         if (!empty($this->responseCode) && isset($this->responseObj['message'])) {
             $message = 'Code: ' . $this->responseCode . '; Message: ' . $this->responseObj['message'];
         } else {
             $message = 'API returned HTTP code of ' . $this->responseCode . ' when fetching from ' . $uri;
         }
         DebugData::$exception = $message;
         $this->debugCallback(DebugData::toArray());
         self::$logger->error($this->responseText);
         // Create better status to show up in logs
         $status .= ': ' . $request->getMethod() . ' ' . $uri;
         if ($request instanceof \Guzzle\Http\Message\EntityEnclosingRequestInterface) {
             $body = $request->getBody();
             if ($body instanceof \Guzzle\Http\EntityBodyInterface) {
                 $status .= ' with Content-Length of ' . $body->getContentLength() . ' and Content-Type of ' . $body->getContentType();
             }
         }
         $exception = new ResponseException($status, $this->responseCode, $uri, DebugData::$opts, $this->responseText);
         $exception->requestObj = $request;
         $exception->responseObj = $response;
         throw $exception;
     }
     $this->debugCallback(DebugData::toArray());
 }
开发者ID:nevetS,项目名称:flame,代码行数:88,代码来源:APIObject.php

示例6: log

 /**
  * Log a message based on a request and response
  *
  * @param RequestInterface $request  Request to log
  * @param Response         $response Response to log
  */
 private function log(RequestInterface $request, Response $response = null)
 {
     $message = '';
     if ($this->settings & self::LOG_CONTEXT) {
         // Log common contextual information
         $message = $request->getHost() . ' - "' . $request->getMethod() . ' ' . $request->getResource() . ' ' . strtoupper($request->getScheme()) . '/' . $request->getProtocolVersion() . '"';
         // If a response is set, then log additional contextual information
         if ($response) {
             $message .= sprintf(' - %s %s - %s %s %s', $response->getStatusCode(), $response->getContentLength() ?: 0, $response->getInfo('total_time'), $response->getInfo('speed_upload'), $response->getInfo('speed_download'));
         }
     }
     // Check if we are logging anything that will come from cURL
     if ($request->getParams()->get('curl_handle') && ($this->settings & self::LOG_DEBUG || $this->settings & self::LOG_HEADERS || $this->settings & self::LOG_BODY)) {
         // If context logging too, then add a new line for cleaner messages
         if ($this->settings & self::LOG_CONTEXT) {
             $message .= "\n";
         }
         // Filter cURL's verbose output based on config settings
         $message .= $this->parseCurlLog($request);
         // Log the response body if the response is available
         if ($this->settings & self::LOG_BODY && $response) {
             if ($request->getParams()->get('response_wire')) {
                 $message .= (string) $request->getParams()->get('response_wire');
             } else {
                 $message .= $response->getBody(true);
             }
         }
     }
     // Send the log message to the adapter, adding a category and host
     $priority = $response && !$response->isSuccessful() ? LOG_ERR : LOG_DEBUG;
     $this->logAdapter->log(trim($message), $priority, array('category' => 'guzzle.request', 'host' => $this->hostname));
 }
开发者ID:nickpeirson,项目名称:guzzle,代码行数:38,代码来源:LogPlugin.php

示例7: getScheme

 /**
  * Get the URI scheme of the request (http, https, ftp, etc)
  *
  * @return string
  */
 public function getScheme()
 {
     return $this->wrapped->getScheme();
 }
开发者ID:cosmorogers,项目名称:http-mock,代码行数:9,代码来源:UnifiedRequest.php


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