/**
  * @dataProvider provideCurlConfig
  */
 public function testParseCurlConfigConvertsStringKeysToConstantKeys($options, $expected)
 {
     $actual = CurlHandle::parseCurlConfig($options);
     $this->assertEquals($expected, $actual);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 public function prepare()
 {
     if (!$this->isPrepared()) {
         if (!$this->client) {
             throw new CommandException('A client must be associated with the command before it can be prepared.');
         }
         // If no response processing value was specified, then attempt to use the highest level of processing
         if (!isset($this[self::RESPONSE_PROCESSING])) {
             $this[self::RESPONSE_PROCESSING] = self::TYPE_MODEL;
         }
         // Notify subscribers of the client that the command is being prepared
         $this->client->dispatch('command.before_prepare', array('command' => $this));
         // Fail on missing required arguments, and change parameters via filters
         $this->validate();
         // Delegate to the subclass that implements the build method
         $this->build();
         // Add custom request headers set on the command
         if ($headers = $this[self::HEADERS_OPTION]) {
             foreach ($headers as $key => $value) {
                 $this->request->setHeader($key, $value);
             }
         }
         // Add any curl options to the request
         if ($options = $this[Client::CURL_OPTIONS]) {
             $this->request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($options));
         }
         // Set a custom response body
         if ($responseBody = $this[self::RESPONSE_BODY]) {
             $this->request->setResponseBody($responseBody);
         }
         $this->client->dispatch('command.after_prepare', array('command' => $this));
     }
     return $this->request;
 }
Example #5
0
 /**
  * Prepare the command for executing and create a request object.
  *
  * @return RequestInterface Returns the generated request
  * @throws CommandException if a client object has not been set previously
  *      or in the prepare()
  */
 public function prepare()
 {
     if (!$this->isPrepared()) {
         if (!$this->client) {
             throw new CommandException('A Client object must be associated with the command before it can be prepared.');
         }
         // Fail on missing required arguments, and change parameters via filters
         $this->apiCommand->validate($this, $this->getInspector());
         $this->build();
         // Add custom request headers set on the command
         if ($headers = $this->get(self::HEADERS_OPTION)) {
             foreach ($headers as $key => $value) {
                 $this->request->setHeader($key, $value);
             }
         }
         // Add any curl options to the request
         $this->request->getCurlOptions()->merge(CurlHandle::parseCurlConfig($this->getAll()));
     }
     return $this->getRequest();
 }
Example #6
0
 public function prepare()
 {
     if (!$this->isPrepared()) {
         if (!$this->client) {
             throw new CommandException('A client must be associated with the command before it can be prepared.');
         }
         if (!isset($this[self::RESPONSE_PROCESSING])) {
             $this[self::RESPONSE_PROCESSING] = self::TYPE_MODEL;
         }
         $this->client->dispatch('command.before_prepare', array('command' => $this));
         $this->validate();
         $this->build();
         if ($headers = $this[self::HEADERS_OPTION]) {
             foreach ($headers as $key => $value) {
                 $this->request->setHeader($key, $value);
             }
         }
         if ($options = $this[Client::CURL_OPTIONS]) {
             $this->request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($options));
         }
         if ($responseBody = $this[self::RESPONSE_BODY]) {
             $this->request->setResponseBody($responseBody);
         }
         $this->client->dispatch('command.after_prepare', array('command' => $this));
     }
     return $this->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);
     // 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;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function prepare()
 {
     if (!$this->isPrepared()) {
         if (!$this->client) {
             throw new CommandException('A client must be associated with the command before it can be prepared.');
         }
         // Notify subscribers of the client that the command is being prepared
         $this->client->dispatch('command.before_prepare', array('command' => $this));
         // Fail on missing required arguments, and change parameters via filters
         $this->validate();
         // Delegate to the subclass that implements the build method
         $this->build();
         // Add custom request headers set on the command
         if ($headers = $this->get(self::HEADERS_OPTION)) {
             foreach ($headers as $key => $value) {
                 $this->request->setHeader($key, $value);
             }
         }
         // Add any curl options to the request
         if ($options = $this->get(Client::CURL_OPTIONS)) {
             $this->request->getCurlOptions()->merge(CurlHandle::parseCurlConfig($options));
         }
         // Set a custom response body
         if ($responseBody = $this->get(self::RESPONSE_BODY)) {
             $this->request->setResponseBody($responseBody);
         }
     }
     return $this->request;
 }