本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getUrl方法的具体用法?PHP RequestInterface::getUrl怎么用?PHP RequestInterface::getUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
/**
* @inheritDoc
*/
public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = [])
{
if (in_array($request->getPath(), $this->paths)) {
$customData = array_merge(['url' => $this->mask((string) $request->getUrl()), 'resource' => $this->mask($request->getResource()), 'request' => $this->mask((string) $request), 'response' => $this->mask((string) $response), 'res_body' => $response ? $this->mask((string) $response) : 'NULL', 'req_body' => $this->mask((string) $request->getBody())], $customData);
}
return parent::format($request, $response, $error, $customData);
}
示例2: getDefaultOptions
protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
{
$url = $request->getUrl();
// Strip fragment from URL. See:
// https://github.com/guzzle/guzzle/issues/453
if (($pos = strpos($url, '#')) !== false) {
$url = substr($url, 0, $pos);
}
$config = $request->getConfig();
$options = array(CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => array($mediator, 'writeResponseBody'), CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'), CURLOPT_READFUNCTION => array($mediator, 'readRequestBody'), CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, '_headers' => $request->getHeaders());
if (defined('CURLOPT_PROTOCOLS')) {
// Allow only HTTP and HTTPS protocols
$options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// Add CURLOPT_ENCODING if Accept-Encoding header is provided
if ($request->hasHeader('Accept-Encoding')) {
$options[CURLOPT_ENCODING] = $request->getHeader('Accept-Encoding');
// Let cURL set the Accept-Encoding header. Without this change
// curl could add a duplicate value.
$this->removeHeader('Accept-Encoding', $options);
}
// cURL sometimes adds a content-type by default. Prevent this.
if (!$request->hasHeader('Content-Type')) {
$options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
}
return $options;
}
示例3: createRingRequest
/**
* Creates a Ring request from a request object.
*
* This function does not hook up the "then" and "progress" events that
* would be required for actually sending a Guzzle request through a
* RingPHP handler.
*
* @param RequestInterface $request Request to convert.
*
* @return array Converted Guzzle Ring request.
*/
public static function createRingRequest(RequestInterface $request)
{
$options = $request->getConfig()->toArray();
$url = $request->getUrl();
// No need to calculate the query string twice (in URL and query).
$qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
}
示例4: execute
/**
* Executes a GuzzleHttp\Message\Request and (if applicable) automatically retries
* when errors occur.
*
* @param Google_Client $client
* @param GuzzleHttp\Message\Request $req
* @return array decoded result
* @throws Google_Service_Exception on server side error (ie: not authenticated,
* invalid or malformed post body, invalid url)
*/
public static function execute(ClientInterface $client, RequestInterface $request, $config = array(), $retryMap = null)
{
$runner = new Google_Task_Runner($config, sprintf('%s %s', $request->getMethod(), $request->getUrl()), array(get_class(), 'doExecute'), array($client, $request));
if (!is_null($retryMap)) {
$runner->setRetryMap($retryMap);
}
return $runner->run();
}
示例5: __construct
/**
* @param string $message
* @param RequestInterface $request
*/
public function __construct($message = null, RequestInterface $request = null)
{
$message = $message ?: $this->message;
if ($request !== null) {
$message .= "\nRequest URL: " . $request->getUrl();
}
parent::__construct($message, $this->code);
}
示例6: __construct
/**
* Gets the relevant data from the Guzzle clients.
*
* @param RequestInterface $request
* @param ResponseInterface $response
*/
public function __construct(RequestInterface $request, ResponseInterface $response)
{
if ($response instanceof FutureResponse) {
$this->httpStatusCode = null;
} else {
$this->httpStatusCode = $response->getStatusCode();
}
$this->requestUrl = $request->getUrl();
}
示例7: getRequestAndQuery
/**
* @param RequestInterface $request
* @return array ['query' => ..., 'request' => ...]
*/
protected function getRequestAndQuery(RequestInterface $request)
{
$query = [];
foreach ($request->getQuery() as $param => $val) {
$query[$param] = $val;
}
$requestInfo = ['url' => $request->getUrl(), 'path' => $request->getPath(), 'queryString' => (string) $request->getQuery(), 'method' => $request->getMethod(), 'hostname' => $request->getHost(), 'port' => $request->getPort(), 'resource' => $request->getResource()];
return ['query' => $query, 'request' => $requestInfo];
}
示例8: buildMessage
/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @return string
*/
protected function buildMessage($request, $response)
{
$resource = $this->getResponseBody();
if (is_null($resource)) {
$resource = '';
}
$message = sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s: %s', $request->getUrl(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase(), $resource);
return $message;
}
示例9: __construct
/**
* @param string $message
* @param RequestInterface $request
* @param ResponseInterface $response
*/
public function __construct($message = null, RequestInterface $request = null, ResponseInterface $response = null)
{
$message = $message ?: $this->message;
if ($request !== null && $response !== null) {
$details = "[url] " . $request->getUrl();
$details .= " [status code] " . $response->getStatusCode();
$details .= " [reason phrase] " . $response->getReasonPhrase();
$details .= ApiResponseException::getErrorDetails($response);
$message .= "\nDetails:\n " . wordwrap($details);
}
parent::__construct($message, $this->code);
}
示例10: create
/**
* Factory method to create a new exception with a normalized error message
*
* @param RequestInterface $request Request
* @param ResponseInterface $response Response received
* @param \Exception $previous Previous exception
*
* @return self
*/
public static function create(RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null)
{
if (!$response) {
return new self('Error completing request', $request, null, $previous);
}
$level = floor($response->getStatusCode() / 100);
if ($level == '4') {
$label = 'Client error response';
$className = __NAMESPACE__ . '\\ClientException';
} elseif ($level == '5') {
$label = 'Server error response';
$className = __NAMESPACE__ . '\\ServerException';
} else {
$label = 'Unsuccessful response';
$className = __CLASS__;
}
$message = $label . ' [url] ' . $request->getUrl() . ' [status code] ' . $response->getStatusCode() . ' [reason phrase] ' . $response->getReasonPhrase();
return new $className($message, $request, $response, $previous);
}
示例11: getDefaultOptions
protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
{
$url = $request->getUrl();
// Strip fragment from URL. See:
// https://github.com/guzzle/guzzle/issues/453
if (($pos = strpos($url, '#')) !== false) {
$url = substr($url, 0, $pos);
}
$config = $request->getConfig();
$options = [CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => [$mediator, 'writeResponseBody'], CURLOPT_HEADERFUNCTION => [$mediator, 'receiveResponseHeader'], CURLOPT_READFUNCTION => [$mediator, 'readRequestBody'], CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, '_headers' => $request->getHeaders()];
if (defined('CURLOPT_PROTOCOLS')) {
// Allow only HTTP and HTTPS protocols
$options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// cURL sometimes adds a content-type by default. Prevent this.
if (!$request->hasHeader('Content-Type')) {
$options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
}
return $options;
}
示例12: send
public function send(RequestInterface $request)
{
$this->logger->info(sprintf('%s "%s"', $request->getMethod(), $request->getUrl()));
$this->logger->debug(sprintf("Request:\n%s", (string) $request));
try {
$response = $this->client->send($request);
} catch (TransferException $e) {
$message = sprintf('Something went wrong when calling vault (%s).', $e->getMessage());
$this->logger->error($message);
throw new ServerException($message);
}
$this->logger->debug(sprintf("Response:\n%s", $response));
if (400 <= $response->getStatusCode()) {
$message = sprintf('Something went wrong when calling vault (%s - %s).', $response->getStatusCode(), $response->getReasonPhrase());
$this->logger->error($message);
$message .= "\n{$response}";
if (500 <= $response->getStatusCode()) {
throw new ServerException($message, $response->getStatusCode(), $response);
}
throw new ClientException($message, $response->getStatusCode(), $response);
}
return $response;
}
示例13: getCacheKey
/**
* Hash a request URL into a string that returns cache metadata
*
* @param RequestInterface $request
*
* @return string
*/
private function getCacheKey(RequestInterface $request)
{
return $this->keyPrefix . md5($request->getMethod() . ' ' . $request->getUrl());
}
示例14: createTimelineMessage
/**
* Build a string for displaying in the time-line containing useful info on the request.
*
* @param RequestInterface $request
* @param ResponseInterface $response
*
* @return string
*/
private function createTimelineMessage(RequestInterface $request, ResponseInterface $response = null)
{
$code = $response ? $response->getStatusCode() : 'NULL';
return sprintf('%s %s (%s)', $request->getMethod(), $request->getUrl(), $code);
}
示例15: setRedirectUrl
/**
* Set the appropriate URL on the request based on the location header
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array $protocols
*/
private function setRedirectUrl(RequestInterface $request, ResponseInterface $response, array $protocols)
{
$location = $response->getHeader('Location');
$location = Url::fromString($location);
// Combine location with the original URL if it is not absolute.
if (!$location->isAbsolute()) {
$originalUrl = Url::fromString($request->getUrl());
// Remove query string parameters and just take what is present on
// the redirect Location header
$originalUrl->getQuery()->clear();
$location = $originalUrl->combine($location);
}
// Ensure that the redirect URL is allowed based on the protocols.
if (!in_array($location->getScheme(), $protocols)) {
throw new BadResponseException(sprintf('Redirect URL, %s, does not use one of the allowed redirect protocols: %s', $location, implode(', ', $protocols)), $request, $response);
}
$request->setUrl($location);
}