public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'json';
     $header = null;
     // Encoding request body into JSON format
     if ($type == 'json') {
         $body = count($body) === 0 ? '{}' : json_encode($body, empty($body) ? JSON_FORCE_OBJECT : 0);
         return $request->setBody($body, 'application/json');
     }
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
示例#2
0
public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;


 if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {

 $operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}

if ($xml) {

 if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
示例#3
0
 /**
  * @param RequestInterface $request
  * @param \Guzzle\Http\EntityBodyInterface|string $body
  * @param array $options
  * @return mixed
  */
 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'raw';
     $header = null;
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $entityBody = EntityBody::factory($value);
     $request->setBody($entityBody);
     $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
     // Add the Content-Encoding header if one is set on the EntityBody
     if ($encoding = $entityBody->getContentEncoding()) {
         $request->setHeader('Content-Encoding', $encoding);
     }
 }
示例#5
0
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
         $request->setBody(json_encode($this->data[$command]));
         unset($this->data[$command]);
     }
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody(json_encode($json))->removeHeader('Expect');
         if ($this->jsonContentType) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
     }
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $request->setBody($this->data[$command]->asXML());
         unset($this->data[$command]);
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $xml = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody($xml->asXML());
         if ($this->contentType) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
         unset($this->data[$command]);
         $request->setBody(json_encode($json));
         // Don't overwrite the Content-Type if one is set
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
     }
 }
示例#10
0
 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'form';
     $header = null;
     if ($type == 'form') {
         // Encoding body into form-urlencoded format
         return $request->addPostFields($body);
     }
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
 public function after(CommandInterface $command, RequestInterface $request)
 {
     $xml = null;
     // If data was found that needs to be serialized, then do so
     if (isset($this->data[$command])) {
         $xml = $this->data[$command]->asXML();
         unset($this->data[$command]);
     } else {
         // Check if XML should always be sent for the command
         $operation = $command->getOperation();
         if ($operation->getData('xmlAllowEmpty')) {
             $xml = $this->createRootElement($operation)->asXML();
         }
     }
     if ($xml) {
         $request->setBody($xml);
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
 }
示例#12
0
protected function visit_body(RequestInterface $request, $value, $flags)
{
if ($request instanceof EntityEnclosingRequestInterface) {
$request->setBody($value);
} else {
throw new InvalidArgumentException('Attempting to set a body on a non-entity-enclosing request');
}
}
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, $key, $value)
 {
     $request->setBody(EntityBody::factory($value));
 }