/**
  * @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);
 }
Example #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 = 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);
         };
     };
 }
Example #3
0
 public function getWaiter($name, array $args = [])
 {
     $config = isset($args['@waiter']) ? $args['@waiter'] : [];
     $config += $this->api->getWaiterConfig($name);
     return new Waiter($this, $name, $args, $config);
 }
 /**
  * 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()));
 }
 public static function _apply_api_provider(callable $value, array &$args, HandlerList $list)
 {
     $api = new Service(ApiProvider::resolve($value, 'api', $args['service'], $args['version']), $value);
     $args['api'] = $api;
     $args['serializer'] = Service::createSerializer($api, $args['endpoint']);
     $args['parser'] = Service::createParser($api);
     $args['error_parser'] = Service::createErrorParser($api->getProtocol());
     $list->prependBuild(Middleware::requestBuilder($args['serializer']), 'builder');
 }
Example #6
0
 /**
  * Applies the listeners needed to parse client models.
  *
  * @param Service $api API to create a parser for
  * @return callable
  * @throws \UnexpectedValueException
  */
 public static function createParser(Service $api)
 {
     static $mapping = ['json' => 'Api\\Api\\Parser\\JsonRpcParser', 'query' => 'Api\\Api\\Parser\\QueryParser', 'rest-json' => 'Api\\Api\\Parser\\RestJsonParser', 'rest-xml' => 'Api\\Api\\Parser\\RestXmlParser'];
     $proto = $api->getProtocol();
     if (isset($mapping[$proto])) {
         return new $mapping[$proto]($api);
     }
     throw new \UnexpectedValueException('Unknown protocol: ' . $api->getProtocol());
 }