Пример #1
0
 /**
  * @param CommandInterface $command Command to serialized
  *
  * @return RequestInterface
  */
 public function __invoke(CommandInterface $command)
 {
     $operation = $this->api->getOperation($command->getName());
     $args = $command->toArray();
     $opts = $this->serialize($operation, $args);
     $uri = $this->buildEndpoint($operation, $args, $opts);
     return new Psr7\Request($operation['http']['method'], $uri, isset($opts['headers']) ? $opts['headers'] : [], isset($opts['body']) ? $opts['body'] : null);
 }
Пример #2
0
 /**
  * Adds a middleware that uses client-side validation.
  *
  * @param Service $api API being accessed.
  *
  * @return callable
  */
 public static function validation(Service $api, Validator $validator = null)
 {
     $validator = $validator ?: new Validator();
     return function (callable $handler) use($api, $validator) {
         return function (CommandInterface $command, RequestInterface $request = null) use($api, $validator, $handler) {
             $operation = $api->getOperation($command->getName());
             $validator->validate($command->getName(), $operation->getInput(), $command->toArray());
             return $handler($command, $request);
         };
     };
 }
Пример #3
0
 /**
  * When invoked with an AWS command, returns a serialization array
  * containing "method", "uri", "headers", and "body" key value pairs.
  *
  * @param CommandInterface $command
  *
  * @return RequestInterface
  */
 public function __invoke(CommandInterface $command)
 {
     $name = $command->getName();
     $operation = $this->api->getOperation($name);
     return new Request($operation['http']['method'], $this->endpoint, ['X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $name, 'Content-Type' => $this->contentType], $this->jsonFormatter->build($operation->getInput(), $command->toArray()));
 }