Ejemplo n.º 1
0
 public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->api->getOperation($command->getName());
     $fn = $this->validator;
     $fn($command->getName(), $operation->getInput(), $command->toArray());
 }
Ejemplo n.º 2
0
 public function __invoke(CommandTransaction $trans)
 {
     $command = $trans->command;
     $name = $command->getName();
     $operation = $this->api->getOperation($name);
     return $trans->client->createRequest($operation['http']['method'], $this->endpoint, ['headers' => ['X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $name, 'Content-Type' => $this->contentType], 'body' => $this->jsonFormatter->build($operation->getInput(), $command->toArray()), 'config' => ['command' => $command]]);
 }
 /**
  * @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);
 }
Ejemplo n.º 4
0
 public function __invoke(CommandTransaction $trans)
 {
     $command = $trans->command;
     $operation = $this->api->getOperation($command->getName());
     $args = $command->toArray();
     $request = $trans->client->createRequest($operation['http']['method'], $this->buildEndpoint($operation, $args), ['config' => ['command' => $command]]);
     // Ensure that query string lists are serialized as duplicates.
     $request->getQuery()->setAggregator($this->aggregator);
     return $this->serialize($request, $operation, $args);
 }
Ejemplo n.º 5
0
 public function onInit(InitEvent $event)
 {
     $c = $event->getCommand();
     $operation = $this->api->getOperation($c->getName());
     $source = $c[$this->sourceParameter];
     if ($source !== null && $operation->getInput()->hasMember($this->bodyParameter)) {
         $c[$this->bodyParameter] = new LazyOpenStream($source, 'r');
         unset($c[$this->sourceParameter]);
     }
 }
 /**
  * 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);
         };
     };
 }
Ejemplo n.º 7
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' => 'Aws\\Api\\Parser\\JsonRpcParser', 'query' => 'Aws\\Api\\Parser\\QueryParser', 'rest-json' => 'Aws\\Api\\Parser\\RestJsonParser', 'rest-xml' => '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());
 }
Ejemplo n.º 8
0
 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');
 }
Ejemplo n.º 9
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()));
 }
Ejemplo n.º 10
0
 private function addSignatureMiddleware()
 {
     // Sign requests. This may need to be modified later to support
     // variable signatures per/operation.
     $this->handlerList->appendSign(Middleware::signer($this->credentialProvider, constantly(SignatureProvider::resolve($this->signatureProvider, $this->config['signature_version'], $this->api->getSigningName(), $this->region))), 'signer');
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 public static function _apply_api_provider($value, array &$args)
 {
     $api = new Service($value, $args['service'], $args['version']);
     $args['api'] = $api;
     $args['error_parser'] = Service::createErrorParser($api->getProtocol());
     $args['serializer'] = Service::createSerializer($api, $args['endpoint']);
 }
Ejemplo n.º 13
0
 private function applyParser()
 {
     $parser = Service::createParser($this->api);
     $this->getEmitter()->on('process', static function (ProcessEvent $e) use($parser) {
         // Guard against exceptions and injected results.
         if ($e->getException() || $e->getResult()) {
             return;
         }
         // Ensure a response exists in order to parse.
         $response = $e->getResponse();
         if (!$response) {
             throw new \RuntimeException('No response was received.');
         }
         $e->setResult($parser($e->getCommand(), $response));
     });
 }