本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getResource方法的具体用法?PHP RequestInterface::getResource怎么用?PHP RequestInterface::getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
/**
* Returns a formatted message
*
* @param RequestInterface $request Request that was sent
* @param Response $response Response that was received
* @param CurlHandle $handle Curl handle associated with the message
* @param array $customData Associative array of custom template data
*
* @return string
*/
public function format(RequestInterface $request, Response $response = null, CurlHandle $handle = null, array $customData = array())
{
$cache = $customData;
return preg_replace_callback('/{\\s*([A-Za-z_\\-\\.0-9]+)\\s*}/', function (array $matches) use($request, $response, $handle, &$cache) {
if (array_key_exists($matches[1], $cache)) {
return $cache[$matches[1]];
}
$result = '';
switch ($matches[1]) {
case 'request':
$result = (string) $request;
break;
case 'response':
$result = (string) $response;
break;
case 'req_body':
$result = $request instanceof EntityEnclosingRequestInterface ? (string) $request->getBody() : '';
break;
case 'res_body':
$result = $response ? $response->getBody(true) : '';
break;
case 'ts':
$result = gmdate('c');
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = (string) $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'protocol':
$result = 'HTTP';
break;
case 'version':
$result = $request->getProtocolVersion();
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'port':
$result = $request->getPort();
break;
case 'code':
$result = $response ? $response->getStatusCode() : '';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : '';
break;
case 'connect_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_CONNECT_TIME);
} elseif ($response) {
$result = $response->getInfo('connect_time');
}
break;
case 'total_time':
if ($handle) {
$result = $handle->getInfo(CURLINFO_TOTAL_TIME);
} elseif ($response) {
$result = $response->getInfo('total_time');
}
break;
case 'curl_error':
$result = $handle ? $handle->getError() : '';
break;
case 'curl_code':
$result = $handle ? $handle->getErrorNo() : '';
break;
case 'curl_stderr':
$result = $handle ? $handle->getStderr() : '';
break;
default:
if (strpos($matches[1], 'req_header_') === 0) {
$result = $request->getHeader(substr($matches[1], 11));
} elseif (strpos($matches[1], 'res_header_') === 0) {
$result = $response->getHeader(substr($matches[1], 11));
}
}
$cache[$matches[1]] = $result;
return $result;
}, $this->template);
}
示例2: 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));
}