/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage A "region" configuration value is required for the "foo" service */ public function testHasSpecificMessageForMissingRegion() { $args = ClientResolver::getDefaultArguments()['region']; $r = new ClientResolver(['region' => $args]); $r->resolve(['service' => 'foo'], new Emitter()); }
/** * The client constructor accepts the following options:. * * - api_provider: (callable) An optional PHP callable that accepts a * type, service, and version argument, and returns an array of * corresponding configuration data. The type value can be one of api, * waiter, or paginator. * - client: (GuzzleHttp\ClientInterface) Optional Guzzle client used to * transfer requests over the wire. If you do not specify a client, the * SDK will create a new client that uses a shared Ring HTTP handler * with other clients. * - credentials: * (array|Vws\Credentials\CredentialsInterface|bool|callable) An * Vws\Credentials\CredentialsInterface object to use with each, an * associative array of "username", "password", and "subscription_token" key value pairs, * `false` to utilize null credentials, or a callable credentials * provider function to create credentials using a function. If no * credentials are provided, the SDK will attempt to load them from the * environment. * - debug: (bool|resource) Set to true to display debug information * when sending requests. Provide a stream resource to write debug * information to a specific resource. * - endpoint: (string) The full URI of the webservice. This is only * required when connecting to a custom endpoint (e.g., a local version * of S3). * - endpoint_provider: (callable) An optional PHP callable that * accepts a hash of options including a service and region key and * returns a hash of endpoint data, of which the endpoint key is * required. * - http: (array) Set to an array of Guzzle client request options * (e.g., proxy, verify, etc.). See * http://docs.guzzlephp.org/en/latest/clients.html#request-options for a * list of available options. * - profile: (string) Allows you to specify which profile to use when * credentials are created from the Vws credentials file in your HOME * directory. This setting overrides the Vws_PROFILE environment * variable. Note: Specifying "profile" will cause the "credentials" key * to be ignored. * - region: (string, required) Region to connect to. * - retries: (int, default=int(3)) Configures the maximum number of * allowed retries for a client (pass 0 to disable retries). * - retry_logger: (string|Psr\Log\LoggerInterface) When the string "debug" * is provided, all retries will be logged to STDOUT. Provide a PSR-3 * logger to log retries to a specific logger instance. * - ringphp_handler: (callable) RingPHP handler used to transfer HTTP * requests (see http://ringphp.readthedocs.org/en/latest/). * - scheme: (string, default=string(5) "https") URI scheme to use when * connecting connect. * - service: (string, required) Name of the service to utilize. This * value will be supplied by default. * - validate: (bool, default=bool(true)) Set to false to disable * client-side parameter validation. * - version: (string, required) The version of the webservice to * utilize (e.g., 2006-03-01). * * @param array $args Client configuration arguments. * * @throws \InvalidArgumentException if any required options are missing */ public function __construct(array $args) { list($service, $exceptionClass) = $this->parseClass(); if (!isset($args['service'])) { $args['service'] = manifest($service)['endpoint']; } if (!isset($args['exception_class'])) { $this->commandException = $exceptionClass; } $resolver = new ClientResolver(static::getArguments()); $config = $resolver->resolve($args, $this->getEmitter()); $this->api = $config['api']; $this->serializer = $config['serializer']; $this->errorParser = $config['error_parser']; $this->endpoint = $config['endpoint']; $this->credentials = $config['credentials']; $this->region = isset($config['region']) ? $config['region'] : null; $this->applyParser(); parent::__construct($config['client'], $config['config']); // Make sure the user agent is prefixed by the SDK version. $client = $this->getHttpClient(); $client->setDefaultOption('allow_redirects', false); $client->setDefaultOption('headers/User-Agent', 'vws-sdk-php/' . Sdk::VERSION . ' ' . Client::getDefaultUserAgent()); if (isset($args['with_resolved'])) { /* @var callable $withResolved */ $args['with_resolved']($config); } }