/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }