本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::setClient方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::setClient方法的具体用法?PHP RequestInterface::setClient怎么用?PHP RequestInterface::setClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::setClient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareRequest
/**
* Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
*
* @param RequestInterface $request Request to prepare for the client
* @param array $options Options to apply to the request
*
* @return RequestInterface
*/
protected function prepareRequest(RequestInterface $request, array $options = array())
{
$request->setClient($this)->setEventDispatcher(clone $this->getEventDispatcher());
if ($curl = $this->config[self::CURL_OPTIONS]) {
$request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($curl));
}
if ($params = $this->config[self::REQUEST_PARAMS]) {
Version::warn('request.params is deprecated. Use request.options to add default request options.');
$request->getParams()->overwriteWith($params);
}
if ($this->userAgent && !$request->hasHeader('User-Agent')) {
$request->setHeader('User-Agent', $this->userAgent);
}
if ($defaults = $this->config[self::REQUEST_OPTIONS]) {
$this->requestFactory->applyOptions($request, $defaults, RequestFactoryInterface::OPTIONS_AS_DEFAULTS);
}
if ($options) {
$this->requestFactory->applyOptions($request, $options);
}
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
}
示例2: prepareRequest
/**
* Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
*
* @param RequestInterface $request Request to prepare for the client
*
* @return RequestInterface
*/
protected function prepareRequest(RequestInterface $request)
{
$request->setClient($this);
// Add any curl options to the request
if ($options = $this->config->get(self::CURL_OPTIONS)) {
$request->getCurlOptions()->merge(CurlHandle::parseCurlConfig($options));
}
// Add request parameters to the request
if ($options = $this->config->get(self::REQUEST_PARAMS)) {
$request->getParams()->merge($options);
}
// Attach client observers to the request
$request->setEventDispatcher(clone $this->getEventDispatcher());
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
}
示例3: prepareRequest
/**
* Prepare a request to be sent from the Client by adding client specific
* behaviors and properties to the request.
*
* @param RequestInterface $request Request to prepare for the client
*
* @return RequestInterface
*/
protected function prepareRequest(RequestInterface $request)
{
$request->setClient($this);
// Add any curl options to the request
$request->getCurlOptions()->merge(CurlHandle::parseCurlConfig($this->config));
foreach ($this->config as $key => $value) {
if (strpos($key, 'params.') === 0) {
// Add request specific parameters to all requests (prefix with 'params.')
$request->getParams()->set(substr($key, 7), $value);
}
}
// Attach client observers to the request
$request->setEventDispatcher(clone $this->getEventDispatcher());
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
}
示例4: prepareRequest
/**
* Prepare a request to be sent from the Client by adding client specific
* behaviors and properties to the request.
*
* @param RequestInterface $request Request to prepare for the client
*
* @return RequestInterface
*/
protected function prepareRequest(RequestInterface $request)
{
$request->setClient($this);
foreach ($this->getConfig()->getAll() as $key => $value) {
if ($key == 'curl.blacklist') {
continue;
}
// Add any curl options that might in the config to the request
if (strpos($key, 'curl.') === 0) {
$curlOption = substr($key, 5);
// Convert constants represented as string to constant int values
if (defined($curlOption)) {
$value = is_string($value) && defined($value) ? constant($value) : $value;
$curlOption = constant($curlOption);
}
$request->getCurlOptions()->set($curlOption, $value);
} elseif (strpos($key, 'params.') === 0) {
// Add request specific parameters to all requests (prefix with 'params.')
$request->getParams()->set(substr($key, 7), $value);
}
}
// Attach client observers to the request
$request->setEventDispatcher(clone $this->getEventDispatcher());
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
}
示例5: prepareRequest
/**
* Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
*
* @param RequestInterface $request Request to prepare for the client
*
* @return RequestInterface
*/
protected function prepareRequest(RequestInterface $request)
{
$request->setClient($this);
// Add any curl options to the request
if ($options = $this->config->get(self::CURL_OPTIONS)) {
$request->getCurlOptions()->merge(CurlHandle::parseCurlConfig($options));
}
// Add request parameters to the request
if ($options = $this->config->get(self::REQUEST_PARAMS)) {
$request->getParams()->merge($options);
}
// Attach client observers to the request
$request->setEventDispatcher(clone $this->getEventDispatcher());
// Set the User-Agent if one is specified on the client but not explicitly on the request
if ($this->userAgent && !$request->hasHeader('User-Agent')) {
$request->setHeader('User-Agent', $this->userAgent);
}
$this->dispatch('client.create_request', array('client' => $this, 'request' => $request));
return $request;
}