args = $args; if (!isset($args['handler']) && !isset($args['http_handler'])) { $this->args['http_handler'] = default_http_handler(); } } public function __call($name, array $args) { $args = isset($args[0]) ? $args[0] : []; if (strpos($name, 'createMultiRegion') === 0) { return $this->createMultiRegionClient(substr($name, 17), $args); } if (strpos($name, 'create') === 0) { return $this->createClient(substr($name, 6), $args); } throw new \BadMethodCallException("Unknown method: {$name}."); } /** * Get a client by name using an array of constructor options. * * @param string $name Service name or namespace (e.g., DynamoDb, s3). * @param array $args Arguments to configure the client. * * @return AwsClientInterface * @throws \InvalidArgumentException if any required options are missing or * the service is not supported. * @see Aws\AwsClient::__construct for a list of available options for args. */ public function createClient($name, array $args = []) { // Get information about the service from the manifest file. $service = manifest($name); $namespace = $service['namespace']; // Instantiate the client class. $client = "Aws\\{$namespace}\\{$namespace}Client"; return new $client($this->mergeArgs($namespace, $service, $args)); } public function createMultiRegionClient($name, array $args = []) { // Get information about the service from the manifest file. $service = manifest($name); $namespace = $service['namespace']; $klass = "Aws\\{$namespace}\\{$namespace}MultiRegionClient"; $klass = class_exists($klass) ? $klass : MultiRegionClient::class; return new $klass($this->mergeArgs($namespace, $service, $args)); } /** * Clone existing SDK instance with ability to pass an associative array * of extra client settings. * * @param array $args * * @return self */ public function copy(array $args = []) { return new self($args + $this->args); } private function mergeArgs($namespace, array $manifest, array $args = []) { // Merge provided args with stored, service-specific args. if (isset($this->args[$namespace])) { $args += $this->args[$namespace]; } // Provide the endpoint prefix in the args. if (!isset($args['service'])) { $args['service'] = $manifest['endpoint']; } return $args + $this->args; } /** * Determine the endpoint prefix from a client namespace. * * @param string $name Namespace name * * @return string * @internal * @deprecated Use the `\Aws\manifest()` function instead. */ public static function getEndpointPrefix($name) { return manifest($name)['endpoint']; } }