Exemplo n.º 1
0
 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     foreach ($this->buffered as $param) {
         $this->visitWithValue($command[$param->getName()], $param, $command);
     }
     $this->buffered = array();
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $additional->setName($key);
                 $this->visitWithValue($value, $additional, $command);
             }
         }
         $additional->setName(null);
     }
     // If data was found that needs to be serialized, then do so
     $xml = null;
     if ($this->writer) {
         $xml = $this->finishDocument($this->writer);
     } elseif ($operation->getData('xmlAllowEmpty')) {
         // Check if XML should always be sent for the command
         $writer = $this->createRootElement($operation);
         $xml = $this->finishDocument($writer);
     }
     if ($xml) {
         $request->setBody(Stream::factory($xml));
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
     $this->writer = null;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  * Replaces the ewayCardNumber field in the body with "X"s.
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = array())
 {
     $body = $request->getBody()->__toString();
     $newBody = preg_replace_callback('/<ewayCardNumber>(.*?)<\\/ewayCardNumber>/', function ($matches) {
         $privateNumber = str_repeat('X', strlen($matches[1]) - 4) . substr($matches[1], -4);
         return '<ewayCardNumber modified>' . $privateNumber . '</ewayCardNumber>';
     }, $body);
     $newRequest = clone $request;
     $newRequest->setBody(Stream::factory($newBody));
     $request->setBody(Stream::factory($body));
     return parent::format($newRequest, $response, $error, $customData);
 }
Exemplo n.º 3
0
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $name = urlencode($param->formName);
     $value = urlencode($command[$param->getName()]);
     $content = Stream::factory($param->filter($value));
     if ($request->getBody() === null) {
         $request->setBody(Stream::factory(""));
     }
     $queryChar = '&';
     if ($request->getBody()->__toString() == '') {
         $queryChar = '';
     }
     $request->getBody()->write($queryChar . $name . "=" . $content);
 }
Exemplo n.º 4
0
 public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $data = $this->jsonData;
     $this->jsonData = null;
     // Add additional parameters to the JSON document
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $data[$key] = $this->prepareValue($value, $additional);
             }
         }
     }
     // 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(Stream::factory(json_encode($data)));
 }
Exemplo n.º 5
0
 protected function payload(RequestInterface $request, StructureShape $member, array $value)
 {
     $request->setHeader('Content-Type', $this->contentType);
     $request->setBody(Stream::factory($this->jsonFormatter->build($member, $value)));
 }
Exemplo n.º 6
0
 private function modifyRedirectRequest(RequestInterface $request, ResponseInterface $response)
 {
     $config = $request->getConfig();
     // Use a GET request if this is an entity enclosing request and we are
     // not forcing RFC compliance, but rather emulating what all browsers
     // would do.
     $statusCode = $response->getStatusCode();
     if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
         $request->setMethod('GET');
         $request->setBody(null);
     }
     $previousUrl = $request->getUrl();
     $this->setRedirectUrl($request, $response);
     $this->rewindEntityBody($request);
     // Add the Referer header if it is told to do so and only
     // add the header if we are not redirecting from https to http.
     if ($config->getPath('redirect/referer') && ($request->getScheme() == 'https' || $request->getScheme() == $config['redirect_scheme'])) {
         $url = Url::fromString($previousUrl);
         $url->setUsername(null);
         $url->setPassword(null);
         $request->setHeader('Referer', (string) $url);
     } else {
         $request->removeHeader('Referer');
     }
 }
 /**
  * @param InputInterface   $input
  * @param RequestInterface $request
  *
  * @return Stream
  * @throws Exception
  */
 protected function addRequestContent(InputInterface $input, RequestInterface $request)
 {
     $type = $input->getOption('request_type');
     if (!is_string($type)) {
         throw new Exception('request_type (-t) is a required parameter when request_content (-c) is used');
     }
     $body = Stream::factory($input->getOption('request_content'));
     $request->setBody($body);
     $request->setHeader('Content-Type', $this->parseContentType($type));
 }
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $value = $command[$param->getName()];
     $request->setBody(Stream::factory($param->filter($value)));
 }
Exemplo n.º 9
0
 private function add_json(RequestInterface $request, $value)
 {
     if (!$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', 'application/json');
     }
     $request->setBody(Stream::factory(json_encode($value)));
 }
 /**
  * @param RequestInterface $request
  * @param string           $name
  * @param mixed            $args
  *
  * @return \GuzzleHttp\Stream\StreamInterface|void
  */
 protected function payload(RequestInterface $request, $name, $args)
 {
     $request->setHeader('Content-Type', 'application/xml');
     $request->setBody(Stream::factory($this->serializer->serialize($args)));
 }
Exemplo n.º 11
0
 /**
  * Apply POST fields and files to a request to attempt to give an accurate
  * representation.
  *
  * @param RequestInterface $request Request to update
  * @param array            $body    Body to apply
  */
 protected function addPostData(RequestInterface $request, array $body)
 {
     static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
     $post = new PostBody();
     foreach ($body as $key => $value) {
         if (isset($fields[gettype($value)])) {
             $post->setField($key, $value);
         } elseif ($value instanceof PostFileInterface) {
             $post->addFile($value);
         } else {
             $post->addFile(new PostFile($key, $value));
         }
     }
     if ($request->getHeader('Content-Type') == 'multipart/form-data') {
         $post->forceMultipartUpload(true);
     }
     $request->setBody($post);
 }
Exemplo n.º 12
0
 private function applyPayload(RequestInterface $request, StructureShape $input, $name, array $args)
 {
     if (!isset($args[$name])) {
         return;
     }
     $m = $input->getMember($name);
     if ($m['streaming'] || ($m['type'] == 'string' || $m['type'] == 'blob')) {
         // Streaming bodies or payloads that are strings are
         // always just a stream of data.
         $request->setBody(Stream::factory($args[$name]));
     } else {
         $this->payload($request, $m, $args[$name]);
     }
 }
Exemplo n.º 13
0
 protected function payload(RequestInterface $request, StructureShape $member, array $value)
 {
     $request->setHeader('Content-Type', 'application/xml');
     $request->setBody(Stream::factory($this->xmlBody->build($member, $value)));
 }
 /**
  * Apply POST fields and files to a request to attempt to give an accurate
  * representation.
  *
  * @param RequestInterface $request Request to update
  * @param array            $body    Body to apply
  */
 protected function addPostData(RequestInterface $request, array $body)
 {
     static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
     $post = new PostBody();
     foreach ($body as $key => $value) {
         if (isset($fields[gettype($value)])) {
             $post->setField($key, $value);
         } elseif ($value instanceof PostFileInterface) {
             $post->addFile($value);
         } else {
             $post->addFile(new PostFile($key, $value));
         }
     }
     $request->setBody($post);
     $post->applyRequestHeaders($request);
 }
Exemplo n.º 15
0
 public function withBody(StreamInterface $stream)
 {
     $this->expectedRequest->setBody($stream);
     return $this;
 }