public function __construct($url, array $config = []) { $this->factories = []; $this->modules = []; $client = new HTTPClient(['base_url' => $url]); parent::__construct($client, $config); }
/** * The SdkClient constructor requires the following constructor options: * * - api: The Api object used to interact with a web service * - credentials: CredentialsInterface object used when signing. * - client: {@see GuzzleHttp\Client} used to send requests. * - signature: string representing the signature version to use (e.g., v4) * - error_parser: A callable that parses response exceptions * - serializer: callable used to serialize a request for a provided * CommandTransaction argument. The callable must return a * RequestInterface object. * * @param array $config Configuration options * * @throws \InvalidArgumentException if any required options are missing */ public function __construct(array $config) { static $required = ['api', 'credentials', 'client', 'signature', 'error_parser', 'endpoint', 'serializer', 'store', 'environment']; foreach ($required as $r) { if (!isset($config[$r])) { throw new \InvalidArgumentException("{$r} is a required option"); } } $this->serializer = $config['serializer']; $this->api = $config['api']; $this->endpoint = $config['endpoint']; $this->credentials = $config['credentials']; $this->signature = $config['signature']; $this->errorParser = $config['error_parser']; $this->store = isset($config['store']) ? $config['store'] : null; $this->environment = isset($config['environment']) ? $config['environment'] : null; $this->defaults = isset($config['defaults']) ? $config['defaults'] : []; $this->commandException = isset($config['exception_class']) ? $config['exception_class'] : 'SellerCenter\\SDK\\Common\\Exception\\SdkException'; parent::__construct($config['client']); }
/** * The client constructor accepts an associative array of configuration * options: * * - defaults: Associative array of default command parameters to add to * each command created by the client. * - validate: Specify if command input is validated (defaults to true). * Changing this setting after the client has been created will have no * effect. * - process: Specify if HTTP responses are parsed (defaults to true). * Changing this setting after the client has been created will have no * effect. * - response_locations: Associative array of location types mapping to * ResponseLocationInterface objects. * - serializer: Optional callable that accepts a CommandTransactions and * returns a serialized request object. * * @param ClientInterface $client HTTP client to use. * @param DescriptionInterface $description Guzzle service description * @param array $config Configuration options */ public function __construct(ClientInterface $client, DescriptionInterface $description, array $config = []) { parent::__construct($client, $config); $this->description = $description; $this->processConfig($config); }
/** * 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); } }