AwsClient.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. namespace Aws;
  3. use Aws\Api\ApiProvider;
  4. use Aws\Api\DocModel;
  5. use Aws\Api\Service;
  6. use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
  7. use Aws\EndpointV2\EndpointProviderV2;
  8. use Aws\EndpointV2\EndpointV2Middleware;
  9. use Aws\Exception\AwsException;
  10. use Aws\Signature\SignatureProvider;
  11. use GuzzleHttp\Psr7\Uri;
  12. /**
  13. * Default AWS client implementation
  14. */
  15. class AwsClient implements AwsClientInterface
  16. {
  17. use AwsClientTrait;
  18. /** @var array */
  19. private $aliases;
  20. /** @var array */
  21. private $config;
  22. /** @var string */
  23. private $region;
  24. /** @var string */
  25. private $endpoint;
  26. /** @var Service */
  27. private $api;
  28. /** @var callable */
  29. private $signatureProvider;
  30. /** @var callable */
  31. private $credentialProvider;
  32. /** @var callable */
  33. private $tokenProvider;
  34. /** @var HandlerList */
  35. private $handlerList;
  36. /** @var array*/
  37. private $defaultRequestOptions;
  38. /** @var array*/
  39. private $clientContextParams = [];
  40. /** @var array*/
  41. protected $clientBuiltIns = [];
  42. /** @var EndpointProviderV2 | callable */
  43. protected $endpointProvider;
  44. /** @var callable */
  45. protected $serializer;
  46. /**
  47. * Get an array of client constructor arguments used by the client.
  48. *
  49. * @return array
  50. */
  51. public static function getArguments()
  52. {
  53. return ClientResolver::getDefaultArguments();
  54. }
  55. /**
  56. * The client constructor accepts the following options:
  57. *
  58. * - api_provider: (callable) An optional PHP callable that accepts a
  59. * type, service, and version argument, and returns an array of
  60. * corresponding configuration data. The type value can be one of api,
  61. * waiter, or paginator.
  62. * - credentials:
  63. * (Aws\Credentials\CredentialsInterface|array|bool|callable) Specifies
  64. * the credentials used to sign requests. Provide an
  65. * Aws\Credentials\CredentialsInterface object, an associative array of
  66. * "key", "secret", and an optional "token" key, `false` to use null
  67. * credentials, or a callable credentials provider used to create
  68. * credentials or return null. See Aws\Credentials\CredentialProvider for
  69. * a list of built-in credentials providers. If no credentials are
  70. * provided, the SDK will attempt to load them from the environment.
  71. * - token:
  72. * (Aws\Token\TokenInterface|array|bool|callable) Specifies
  73. * the token used to authorize requests. Provide an
  74. * Aws\Token\TokenInterface object, an associative array of
  75. * "token" and an optional "expires" key, `false` to use no
  76. * token, or a callable token provider used to create a
  77. * token or return null. See Aws\Token\TokenProvider for
  78. * a list of built-in token providers. If no token is
  79. * provided, the SDK will attempt to load one from the environment.
  80. * - csm:
  81. * (Aws\ClientSideMonitoring\ConfigurationInterface|array|callable) Specifies
  82. * the credentials used to sign requests. Provide an
  83. * Aws\ClientSideMonitoring\ConfigurationInterface object, a callable
  84. * configuration provider used to create client-side monitoring configuration,
  85. * `false` to disable csm, or an associative array with the following keys:
  86. * enabled: (bool) Set to true to enable client-side monitoring, defaults
  87. * to false; host: (string) the host location to send monitoring events to,
  88. * defaults to 127.0.0.1; port: (int) The port used for the host connection,
  89. * defaults to 31000; client_id: (string) An identifier for this project
  90. * - debug: (bool|array) Set to true to display debug information when
  91. * sending requests. Alternatively, you can provide an associative array
  92. * with the following keys: logfn: (callable) Function that is invoked
  93. * with log messages; stream_size: (int) When the size of a stream is
  94. * greater than this number, the stream data will not be logged (set to
  95. * "0" to not log any stream data); scrub_auth: (bool) Set to false to
  96. * disable the scrubbing of auth data from the logged messages; http:
  97. * (bool) Set to false to disable the "debug" feature of lower level HTTP
  98. * adapters (e.g., verbose curl output).
  99. * - stats: (bool|array) Set to true to gather transfer statistics on
  100. * requests sent. Alternatively, you can provide an associative array with
  101. * the following keys: retries: (bool) Set to false to disable reporting
  102. * on retries attempted; http: (bool) Set to true to enable collecting
  103. * statistics from lower level HTTP adapters (e.g., values returned in
  104. * GuzzleHttp\TransferStats). HTTP handlers must support an
  105. * `http_stats_receiver` option for this to have an effect; timer: (bool)
  106. * Set to true to enable a command timer that reports the total wall clock
  107. * time spent on an operation in seconds.
  108. * - disable_host_prefix_injection: (bool) Set to true to disable host prefix
  109. * injection logic for services that use it. This disables the entire
  110. * prefix injection, including the portions supplied by user-defined
  111. * parameters. Setting this flag will have no effect on services that do
  112. * not use host prefix injection.
  113. * - endpoint: (string) The full URI of the webservice. This is only
  114. * required when connecting to a custom endpoint (e.g., a local version
  115. * of S3).
  116. * - endpoint_discovery: (Aws\EndpointDiscovery\ConfigurationInterface,
  117. * Aws\CacheInterface, array, callable) Settings for endpoint discovery.
  118. * Provide an instance of Aws\EndpointDiscovery\ConfigurationInterface,
  119. * an instance Aws\CacheInterface, a callable that provides a promise for
  120. * a Configuration object, or an associative array with the following
  121. * keys: enabled: (bool) Set to true to enable endpoint discovery, false
  122. * to explicitly disable it, defaults to false; cache_limit: (int) The
  123. * maximum number of keys in the endpoints cache, defaults to 1000.
  124. * - endpoint_provider: (callable) An optional PHP callable that
  125. * accepts a hash of options including a "service" and "region" key and
  126. * returns NULL or a hash of endpoint data, of which the "endpoint" key
  127. * is required. See Aws\Endpoint\EndpointProvider for a list of built-in
  128. * providers.
  129. * - handler: (callable) A handler that accepts a command object,
  130. * request object and returns a promise that is fulfilled with an
  131. * Aws\ResultInterface object or rejected with an
  132. * Aws\Exception\AwsException. A handler does not accept a next handler
  133. * as it is terminal and expected to fulfill a command. If no handler is
  134. * provided, a default Guzzle handler will be utilized.
  135. * - http: (array, default=array(0)) Set to an array of SDK request
  136. * options to apply to each request (e.g., proxy, verify, etc.).
  137. * - http_handler: (callable) An HTTP handler is a function that
  138. * accepts a PSR-7 request object and returns a promise that is fulfilled
  139. * with a PSR-7 response object or rejected with an array of exception
  140. * data. NOTE: This option supersedes any provided "handler" option.
  141. * - idempotency_auto_fill: (bool|callable) Set to false to disable SDK to
  142. * populate parameters that enabled 'idempotencyToken' trait with a random
  143. * UUID v4 value on your behalf. Using default value 'true' still allows
  144. * parameter value to be overwritten when provided. Note: auto-fill only
  145. * works when cryptographically secure random bytes generator functions
  146. * (random_bytes, openssl_random_pseudo_bytes or mcrypt_create_iv) can be
  147. * found. You may also provide a callable source of random bytes.
  148. * - profile: (string) Allows you to specify which profile to use when
  149. * credentials are created from the AWS credentials file in your HOME
  150. * directory. This setting overrides the AWS_PROFILE environment
  151. * variable. Note: Specifying "profile" will cause the "credentials" key
  152. * to be ignored.
  153. * - region: (string, required) Region to connect to. See
  154. * http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of
  155. * available regions.
  156. * - retries: (int, Aws\Retry\ConfigurationInterface, Aws\CacheInterface,
  157. * array, callable) Configures the retry mode and maximum number of
  158. * allowed retries for a client (pass 0 to disable retries). Provide an
  159. * integer for 'legacy' mode with the specified number of retries.
  160. * Otherwise provide an instance of Aws\Retry\ConfigurationInterface, an
  161. * instance of Aws\CacheInterface, a callable function, or an array with
  162. * the following keys: mode: (string) Set to 'legacy', 'standard' (uses
  163. * retry quota management), or 'adapative' (an experimental mode that adds
  164. * client-side rate limiting to standard mode); max_attempts (int) The
  165. * maximum number of attempts for a given request.
  166. * - scheme: (string, default=string(5) "https") URI scheme to use when
  167. * connecting connect. The SDK will utilize "https" endpoints (i.e.,
  168. * utilize SSL/TLS connections) by default. You can attempt to connect to
  169. * a service over an unencrypted "http" endpoint by setting ``scheme`` to
  170. * "http".
  171. * - signature_provider: (callable) A callable that accepts a signature
  172. * version name (e.g., "v4"), a service name, and region, and
  173. * returns a SignatureInterface object or null. This provider is used to
  174. * create signers utilized by the client. See
  175. * Aws\Signature\SignatureProvider for a list of built-in providers
  176. * - signature_version: (string) A string representing a custom
  177. * signature version to use with a service (e.g., v4). Note that
  178. * per/operation signature version MAY override this requested signature
  179. * version.
  180. * - use_aws_shared_config_files: (bool, default=bool(true)) Set to false to
  181. * disable checking for shared config file in '~/.aws/config' and
  182. * '~/.aws/credentials'. This will override the AWS_CONFIG_FILE
  183. * environment variable.
  184. * - validate: (bool, default=bool(true)) Set to false to disable
  185. * client-side parameter validation.
  186. * - version: (string, required) The version of the webservice to
  187. * utilize (e.g., 2006-03-01).
  188. *
  189. * @param array $args Client configuration arguments.
  190. *
  191. * @throws \InvalidArgumentException if any required options are missing or
  192. * the service is not supported.
  193. */
  194. public function __construct(array $args)
  195. {
  196. list($service, $exceptionClass) = $this->parseClass();
  197. if (!isset($args['service'])) {
  198. $args['service'] = manifest($service)['endpoint'];
  199. }
  200. if (!isset($args['exception_class'])) {
  201. $args['exception_class'] = $exceptionClass;
  202. }
  203. $this->handlerList = new HandlerList();
  204. $resolver = new ClientResolver(static::getArguments());
  205. $config = $resolver->resolve($args, $this->handlerList);
  206. $this->api = $config['api'];
  207. $this->signatureProvider = $config['signature_provider'];
  208. $this->endpoint = new Uri($config['endpoint']);
  209. $this->credentialProvider = $config['credentials'];
  210. $this->tokenProvider = $config['token'];
  211. $this->region = isset($config['region']) ? $config['region'] : null;
  212. $this->config = $config['config'];
  213. $this->setClientBuiltIns($args);
  214. $this->clientContextParams = $this->setClientContextParams($args);
  215. $this->defaultRequestOptions = $config['http'];
  216. $this->endpointProvider = $config['endpoint_provider'];
  217. $this->serializer = $config['serializer'];
  218. $this->addSignatureMiddleware();
  219. $this->addInvocationId();
  220. $this->addEndpointParameterMiddleware($args);
  221. $this->addEndpointDiscoveryMiddleware($config, $args);
  222. $this->addRequestCompressionMiddleware($config);
  223. $this->loadAliases();
  224. $this->addStreamRequestPayload();
  225. $this->addRecursionDetection();
  226. if ($this->isUseEndpointV2()) {
  227. $this->addEndpointV2Middleware();
  228. }
  229. if (!is_null($this->api->getMetadata('awsQueryCompatible'))) {
  230. $this->addQueryCompatibleInputMiddleware($this->api);
  231. }
  232. if (isset($args['with_resolved'])) {
  233. $args['with_resolved']($config);
  234. }
  235. }
  236. public function getHandlerList()
  237. {
  238. return $this->handlerList;
  239. }
  240. public function getConfig($option = null)
  241. {
  242. return $option === null
  243. ? $this->config
  244. : (isset($this->config[$option])
  245. ? $this->config[$option]
  246. : null);
  247. }
  248. public function getCredentials()
  249. {
  250. $fn = $this->credentialProvider;
  251. return $fn();
  252. }
  253. public function getEndpoint()
  254. {
  255. return $this->endpoint;
  256. }
  257. public function getRegion()
  258. {
  259. return $this->region;
  260. }
  261. public function getApi()
  262. {
  263. return $this->api;
  264. }
  265. public function getCommand($name, array $args = [])
  266. {
  267. // Fail fast if the command cannot be found in the description.
  268. if (!isset($this->getApi()['operations'][$name])) {
  269. $name = ucfirst($name);
  270. if (!isset($this->getApi()['operations'][$name])) {
  271. throw new \InvalidArgumentException("Operation not found: $name");
  272. }
  273. }
  274. if (!isset($args['@http'])) {
  275. $args['@http'] = $this->defaultRequestOptions;
  276. } else {
  277. $args['@http'] += $this->defaultRequestOptions;
  278. }
  279. return new Command($name, $args, clone $this->getHandlerList());
  280. }
  281. public function getEndpointProvider()
  282. {
  283. return $this->endpointProvider;
  284. }
  285. /**
  286. * Provides the set of service context parameter
  287. * key-value pairs used for endpoint resolution.
  288. *
  289. * @return array
  290. */
  291. public function getClientContextParams()
  292. {
  293. return $this->clientContextParams;
  294. }
  295. /**
  296. * Provides the set of built-in keys and values
  297. * used for endpoint resolution
  298. *
  299. * @return array
  300. */
  301. public function getClientBuiltIns()
  302. {
  303. return $this->clientBuiltIns;
  304. }
  305. public function __sleep()
  306. {
  307. throw new \RuntimeException('Instances of ' . static::class
  308. . ' cannot be serialized');
  309. }
  310. /**
  311. * Get the signature_provider function of the client.
  312. *
  313. * @return callable
  314. */
  315. final public function getSignatureProvider()
  316. {
  317. return $this->signatureProvider;
  318. }
  319. /**
  320. * Parse the class name and setup the custom exception class of the client
  321. * and return the "service" name of the client and "exception_class".
  322. *
  323. * @return array
  324. */
  325. private function parseClass()
  326. {
  327. $klass = get_class($this);
  328. if ($klass === __CLASS__) {
  329. return ['', AwsException::class];
  330. }
  331. $service = substr($klass, strrpos($klass, '\\') + 1, -6);
  332. return [
  333. strtolower($service),
  334. "Aws\\{$service}\\Exception\\{$service}Exception"
  335. ];
  336. }
  337. private function addEndpointParameterMiddleware($args)
  338. {
  339. if (empty($args['disable_host_prefix_injection'])) {
  340. $list = $this->getHandlerList();
  341. $list->appendBuild(
  342. EndpointParameterMiddleware::wrap(
  343. $this->api
  344. ),
  345. 'endpoint_parameter'
  346. );
  347. }
  348. }
  349. private function addEndpointDiscoveryMiddleware($config, $args)
  350. {
  351. $list = $this->getHandlerList();
  352. if (!isset($args['endpoint'])) {
  353. $list->appendBuild(
  354. EndpointDiscoveryMiddleware::wrap(
  355. $this,
  356. $args,
  357. $config['endpoint_discovery']
  358. ),
  359. 'EndpointDiscoveryMiddleware'
  360. );
  361. }
  362. }
  363. private function addSignatureMiddleware()
  364. {
  365. $api = $this->getApi();
  366. $provider = $this->signatureProvider;
  367. $version = $this->config['signature_version'];
  368. $name = $this->config['signing_name'];
  369. $region = $this->config['signing_region'];
  370. $resolver = static function (
  371. CommandInterface $c
  372. ) use ($api, $provider, $name, $region, $version) {
  373. if (!empty($c['@context']['signing_region'])) {
  374. $region = $c['@context']['signing_region'];
  375. }
  376. if (!empty($c['@context']['signing_service'])) {
  377. $name = $c['@context']['signing_service'];
  378. }
  379. $authType = $api->getOperation($c->getName())['authtype'];
  380. switch ($authType){
  381. case 'none':
  382. $version = 'anonymous';
  383. break;
  384. case 'v4-unsigned-body':
  385. $version = 'v4-unsigned-body';
  386. break;
  387. case 'bearer':
  388. $version = 'bearer';
  389. break;
  390. }
  391. if (isset($c['@context']['signature_version'])) {
  392. if ($c['@context']['signature_version'] == 'v4a') {
  393. $version = 'v4a';
  394. }
  395. }
  396. if (!empty($endpointAuthSchemes = $c->getAuthSchemes())) {
  397. $version = $endpointAuthSchemes['version'];
  398. $name = isset($endpointAuthSchemes['name']) ?
  399. $endpointAuthSchemes['name'] : $name;
  400. $region = isset($endpointAuthSchemes['region']) ?
  401. $endpointAuthSchemes['region'] : $region;
  402. }
  403. return SignatureProvider::resolve($provider, $version, $name, $region);
  404. };
  405. $this->handlerList->appendSign(
  406. Middleware::signer($this->credentialProvider,
  407. $resolver,
  408. $this->tokenProvider,
  409. $this->getConfig()
  410. ),
  411. 'signer'
  412. );
  413. }
  414. private function addRequestCompressionMiddleware($config)
  415. {
  416. if (empty($config['disable_request_compression'])) {
  417. $list = $this->getHandlerList();
  418. $list->appendBuild(
  419. RequestCompressionMiddleware::wrap($config),
  420. 'request-compression'
  421. );
  422. }
  423. }
  424. private function addQueryCompatibleInputMiddleware(Service $api)
  425. {
  426. $list = $this->getHandlerList();
  427. $list->appendValidate(
  428. QueryCompatibleInputMiddleware::wrap($api),
  429. 'query-compatible-input'
  430. );
  431. }
  432. private function addInvocationId()
  433. {
  434. // Add invocation id to each request
  435. $this->handlerList->prependSign(Middleware::invocationId(), 'invocation-id');
  436. }
  437. private function loadAliases($file = null)
  438. {
  439. if (!isset($this->aliases)) {
  440. if (is_null($file)) {
  441. $file = __DIR__ . '/data/aliases.json';
  442. }
  443. $aliases = \Aws\load_compiled_json($file);
  444. $serviceId = $this->api->getServiceId();
  445. $version = $this->getApi()->getApiVersion();
  446. if (!empty($aliases['operations'][$serviceId][$version])) {
  447. $this->aliases = array_flip($aliases['operations'][$serviceId][$version]);
  448. }
  449. }
  450. }
  451. private function addStreamRequestPayload()
  452. {
  453. $streamRequestPayloadMiddleware = StreamRequestPayloadMiddleware::wrap(
  454. $this->api
  455. );
  456. $this->handlerList->prependSign(
  457. $streamRequestPayloadMiddleware,
  458. 'StreamRequestPayloadMiddleware'
  459. );
  460. }
  461. private function addRecursionDetection()
  462. {
  463. // Add recursion detection header to requests
  464. // originating in supported Lambda runtimes
  465. $this->handlerList->appendBuild(
  466. Middleware::recursionDetection(), 'recursion-detection'
  467. );
  468. }
  469. private function addEndpointV2Middleware()
  470. {
  471. $list = $this->getHandlerList();
  472. $endpointArgs = $this->getEndpointProviderArgs();
  473. $list->prependBuild(
  474. EndpointV2Middleware::wrap(
  475. $this->endpointProvider,
  476. $this->getApi(),
  477. $endpointArgs
  478. ),
  479. 'endpoint-resolution'
  480. );
  481. }
  482. /**
  483. * Retrieves client context param definition from service model,
  484. * creates mapping of client context param names with client-provided
  485. * values.
  486. *
  487. * @return array
  488. */
  489. private function setClientContextParams($args)
  490. {
  491. $api = $this->getApi();
  492. $resolvedParams = [];
  493. if (!empty($paramDefinitions = $api->getClientContextParams())) {
  494. foreach($paramDefinitions as $paramName => $paramValue) {
  495. if (isset($args[$paramName])) {
  496. $result[$paramName] = $args[$paramName];
  497. }
  498. }
  499. }
  500. return $resolvedParams;
  501. }
  502. /**
  503. * Retrieves and sets default values used for endpoint resolution.
  504. */
  505. private function setClientBuiltIns($args)
  506. {
  507. $builtIns = [];
  508. $config = $this->getConfig();
  509. $service = $args['service'];
  510. $builtIns['SDK::Endpoint'] = isset($args['endpoint']) ? $args['endpoint'] : null;
  511. $builtIns['AWS::Region'] = $this->getRegion();
  512. $builtIns['AWS::UseFIPS'] = $config['use_fips_endpoint']->isUseFipsEndpoint();
  513. $builtIns['AWS::UseDualStack'] = $config['use_dual_stack_endpoint']->isUseDualstackEndpoint();
  514. if ($service === 's3' || $service === 's3control'){
  515. $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
  516. }
  517. if ($service === 's3') {
  518. $builtIns['AWS::S3::UseArnRegion'] = $config['use_arn_region']->isUseArnRegion();
  519. $builtIns['AWS::S3::Accelerate'] = $config['use_accelerate_endpoint'];
  520. $builtIns['AWS::S3::ForcePathStyle'] = $config['use_path_style_endpoint'];
  521. $builtIns['AWS::S3::DisableMultiRegionAccessPoints'] = $config['disable_multiregion_access_points'];
  522. }
  523. $this->clientBuiltIns += $builtIns;
  524. }
  525. /**
  526. * Retrieves arguments to be used in endpoint resolution.
  527. *
  528. * @return array
  529. */
  530. public function getEndpointProviderArgs()
  531. {
  532. return $this->normalizeEndpointProviderArgs();
  533. }
  534. /**
  535. * Combines built-in and client context parameter values in
  536. * order of specificity. Client context parameter values supersede
  537. * built-in values.
  538. *
  539. * @return array
  540. */
  541. private function normalizeEndpointProviderArgs()
  542. {
  543. $normalizedBuiltIns = [];
  544. foreach($this->clientBuiltIns as $name => $value) {
  545. $normalizedName = explode('::', $name);
  546. $normalizedName = $normalizedName[count($normalizedName) - 1];
  547. $normalizedBuiltIns[$normalizedName] = $value;
  548. }
  549. return array_merge($normalizedBuiltIns, $this->getClientContextParams());
  550. }
  551. protected function isUseEndpointV2()
  552. {
  553. return $this->endpointProvider instanceof EndpointProviderV2;
  554. }
  555. public static function emitDeprecationWarning() {
  556. $phpVersion = PHP_VERSION_ID;
  557. if ($phpVersion < 70205) {
  558. $phpVersionString = phpversion();
  559. @trigger_error(
  560. "This installation of the SDK is using PHP version"
  561. . " {$phpVersionString}, which will be deprecated on August"
  562. . " 15th, 2023. Please upgrade your PHP version to a minimum of"
  563. . " 7.2.5 before then to continue receiving updates to the AWS"
  564. . " SDK for PHP. To disable this warning, set"
  565. . " suppress_php_deprecation_warning to true on the client constructor"
  566. . " or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING"
  567. . " to true.",
  568. E_USER_DEPRECATED
  569. );
  570. }
  571. }
  572. /**
  573. * Returns a service model and doc model with any necessary changes
  574. * applied.
  575. *
  576. * @param array $api Array of service data being documented.
  577. * @param array $docs Array of doc model data.
  578. *
  579. * @return array Tuple containing a [Service, DocModel]
  580. *
  581. * @internal This should only used to document the service API.
  582. * @codeCoverageIgnore
  583. */
  584. public static function applyDocFilters(array $api, array $docs)
  585. {
  586. $aliases = \Aws\load_compiled_json(__DIR__ . '/data/aliases.json');
  587. $serviceId = $api['metadata']['serviceId'];
  588. $version = $api['metadata']['apiVersion'];
  589. // Replace names for any operations with SDK aliases
  590. if (!empty($aliases['operations'][$serviceId][$version])) {
  591. foreach ($aliases['operations'][$serviceId][$version] as $op => $alias) {
  592. $api['operations'][$alias] = $api['operations'][$op];
  593. $docs['operations'][$alias] = $docs['operations'][$op];
  594. unset($api['operations'][$op], $docs['operations'][$op]);
  595. }
  596. }
  597. ksort($api['operations']);
  598. return [
  599. new Service($api, ApiProvider::defaultProvider()),
  600. new DocModel($docs)
  601. ];
  602. }
  603. /**
  604. * @deprecated
  605. * @return static
  606. */
  607. public static function factory(array $config = [])
  608. {
  609. return new static($config);
  610. }
  611. }