本文整理匯總了PHP中Guzzle\Http\Message\RequestInterface::setEventDispatcher方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestInterface::setEventDispatcher方法的具體用法?PHP RequestInterface::setEventDispatcher怎麽用?PHP RequestInterface::setEventDispatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::setEventDispatcher方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
*
* @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;
}
示例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
$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;
}
示例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);
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;
}
示例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);
// 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;
}