Exemplo n.º 1
0
 /**
  * Prepares and returns guzzle options array for next call
  *
  * @param ServiceRequestInterface $request
  * @param null|string             $httpMethod
  * @return array
  */
 protected function prepareGuzzleOptions(ServiceRequestInterface $request, $httpMethod = null)
 {
     if ($this->isMultipartFormRequest()) {
         $this->enableMultipart();
     } else {
         $this->disableMultipart();
     }
     $headers = $request->getHeaders() ?: [];
     if ($this->debugUser) {
         $headers = array_merge($headers, ['debug-user' => $this->debugUser]);
     } else {
         if (array_key_exists('debug-user', $headers)) {
             unset($headers['debug-user']);
         }
     }
     $request->setHeaders($headers);
     return parent::prepareGuzzleOptions($request, $httpMethod);
 }
Exemplo n.º 2
0
 /**
  * Takes the current request and supplements it with the service's defaults
  * to merge them into a complete request.
  */
 protected function supplementRequestWithDefaults()
 {
     // properties to set only if they are empty
     if (empty($this->request->getLocation())) {
         $this->request->setLocation($this->defaults->getLocation());
     }
     if (empty($this->request->getMethod())) {
         $this->request->setMethod($this->defaults->getMethod());
     }
     if (empty($this->request->getParameters())) {
         $this->request->setParameters($this->defaults->getParameters());
     }
     if (empty($this->request->getBody())) {
         $this->request->setBody($this->defaults->getBody());
     }
     if ($this->credentialsAreEmpty($this->request->getCredentials()) && !$this->credentialsAreEmpty($this->defaults->getCredentials())) {
         $this->request->setCredentials($this->defaults->getCredentials()['name'], $this->defaults->getCredentials()['password'], $this->defaults->getCredentials()['domain']);
     }
     // properties to expand
     if (!empty($this->defaults->getHeaders())) {
         $this->request->setHeaders(array_merge($this->request->getHeaders(), $this->defaults->getHeaders()));
     }
 }