/**
  * @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
 /**
  * Gets the JSON Content-Type header for a service API
  *
  * @param Service $service
  *
  * @return string
  */
 public static function getContentType(Service $service)
 {
     return 'application/x-amz-json-' . number_format($service->getMetadata('jsonVersion'), 1);
 }
 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');
 }
示例#5
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' => 'ILAB_Aws\\Api\\Parser\\JsonRpcParser', 'query' => 'ILAB_Aws\\Api\\Parser\\QueryParser', 'rest-json' => 'ILAB_Aws\\Api\\Parser\\RestJsonParser', 'rest-xml' => 'ILAB_Aws\\Api\\Parser\\RestXmlParser'];
     $proto = $api->getProtocol();
     if (isset($mapping[$proto])) {
         return new $mapping[$proto]($api);
     } elseif ($proto == 'ec2') {
         return new QueryParser($api, null, false);
     }
     throw new \UnexpectedValueException('Unknown protocol: ' . $api->getProtocol());
 }
 /**
  * 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()));
 }