Example #1
0
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $value = $param->filter($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);
     }
 }
Example #2
0
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command])) {
         // Don't overwrite the Content-Type if one is set
         if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->jsonContentType);
         }
         $request->setBody(json_encode($this->data[$command]));
         unset($this->data[$command]);
     }
 }
Example #3
0
 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->finishDocument($this->data[$command]);
         unset($this->data[$command]);
     } else {
         // Check if XML should always be sent for the command
         $operation = $command->getOperation();
         if ($operation->getData('xmlAllowEmpty')) {
             $xmlWriter = $this->createRootElement($operation);
             $xml = $this->finishDocument($xmlWriter);
         }
     }
     if ($xml) {
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
         $request->setBody($xml);
     }
 }
Example #4
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');
     }
 }