@@ -47,6 +47,20 @@ class ClientResolver
47
47
/** @var array */
48
48
private $ argDefinitions ;
49
49
50
+ /**
51
+ * When using this option as default please make sure that, your config
52
+ * has at least one data type defined in `valid` otherwise it will be
53
+ * defaulted to `string`. Also, the default value will be the falsy value
54
+ * based on the resolved data type. For example, the default for `string`
55
+ * will be `''` and for bool will be `false`.
56
+ *
57
+ * @var string
58
+ */
59
+ const DEFAULT_FROM_ENV_INI = [
60
+ __CLASS__ ,
61
+ '_resolve_from_env_ini '
62
+ ];
63
+
50
64
/** @var array Map of types to a corresponding function */
51
65
private static $ typeMap = [
52
66
'resource ' => 'is_resource ' ,
@@ -91,7 +105,7 @@ class ClientResolver
91
105
'valid ' => ['bool ' ],
92
106
'doc ' => 'Set to true to disable endpoint urls configured using `AWS_ENDPOINT_URL` and `endpoint_url` shared config option. ' ,
93
107
'fn ' => [__CLASS__ , '_apply_ignore_configured_endpoint_urls ' ],
94
- 'default ' => [ __CLASS__ , ' _default_ignore_configured_endpoint_urls ' ] ,
108
+ 'default ' => self :: DEFAULT_FROM_ENV_INI ,
95
109
],
96
110
'endpoint ' => [
97
111
'type ' => 'value ' ,
@@ -105,7 +119,7 @@ class ClientResolver
105
119
'valid ' => ['string ' ],
106
120
'doc ' => 'Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. ' ,
107
121
'fn ' => [__CLASS__ , '_apply_region ' ],
108
- 'default ' => [ __CLASS__ , ' _default_region ' ]
122
+ 'default ' => self :: DEFAULT_FROM_ENV_INI
109
123
],
110
124
'version ' => [
111
125
'type ' => 'value ' ,
@@ -244,7 +258,7 @@ class ClientResolver
244
258
'valid ' => ['bool ' , 'callable ' ],
245
259
'doc ' => 'Set to true to disable request compression for supported operations ' ,
246
260
'fn ' => [__CLASS__ , '_apply_disable_request_compression ' ],
247
- 'default ' => [ __CLASS__ , ' _default_disable_request_compression ' ] ,
261
+ 'default ' => self :: DEFAULT_FROM_ENV_INI ,
248
262
],
249
263
'request_min_compression_size_bytes ' => [
250
264
'type ' => 'value ' ,
@@ -324,10 +338,10 @@ class ClientResolver
324
338
],
325
339
'sigv4a_signing_region_set ' => [
326
340
'type ' => 'value ' ,
327
- 'valid ' => ['array ' , 'string ' ],
341
+ 'valid ' => ['string ' , 'array ' ],
328
342
'doc ' => 'A comma-delimited list of supported regions sent in sigv4a requests. ' ,
329
343
'fn ' => [__CLASS__ , '_apply_sigv4a_signing_region_set ' ],
330
- 'default ' => [ __CLASS__ , ' _default_sigv4a_signing_region_set ' ]
344
+ 'default ' => self :: DEFAULT_FROM_ENV_INI
331
345
]
332
346
];
333
347
@@ -397,7 +411,15 @@ public function resolve(array $args, HandlerList $list)
397
411
|| $ a ['default ' ] instanceof \Closure
398
412
)
399
413
) {
400
- $ args [$ key ] = $ a ['default ' ]($ args );
414
+ if ($ a ['default ' ] === self ::DEFAULT_FROM_ENV_INI ) {
415
+ $ args [$ key ] = $ a ['default ' ](
416
+ $ key ,
417
+ $ a ['valid ' ][0 ] ?? 'string ' ,
418
+ $ args
419
+ );
420
+ } else {
421
+ $ args [$ key ] = $ a ['default ' ]($ args );
422
+ }
401
423
} else {
402
424
$ args [$ key ] = $ a ['default ' ];
403
425
}
@@ -590,15 +612,6 @@ public static function _apply_disable_request_compression($value, array &$args)
590
612
$ args ['config ' ]['disable_request_compression ' ] = $ value ;
591
613
}
592
614
593
- public static function _default_disable_request_compression (array &$ args ) {
594
- return ConfigurationResolver::resolve (
595
- 'disable_request_compression ' ,
596
- false ,
597
- 'bool ' ,
598
- $ args
599
- );
600
- }
601
-
602
615
public static function _apply_min_compression_size ($ value , array &$ args ) {
603
616
if (is_callable ($ value )) {
604
617
$ value = $ value ();
@@ -1259,16 +1272,6 @@ public static function _apply_suppress_php_deprecation_warning($value, &$args)
1259
1272
}
1260
1273
}
1261
1274
1262
- public static function _default_ignore_configured_endpoint_urls (array &$ args )
1263
- {
1264
- return ConfigurationResolver::resolve (
1265
- 'ignore_configured_endpoint_urls ' ,
1266
- false ,
1267
- 'bool ' ,
1268
- $ args
1269
- );
1270
- }
1271
-
1272
1275
public static function _default_endpoint (array &$ args )
1273
1276
{
1274
1277
if ($ args ['config ' ]['ignore_configured_endpoint_urls ' ]
@@ -1318,15 +1321,6 @@ public static function _apply_sigv4a_signing_region_set($value, array &$args)
1318
1321
}
1319
1322
}
1320
1323
1321
- public static function _default_sigv4a_signing_region_set (array &$ args )
1322
- {
1323
- return ConfigurationResolver::resolve (
1324
- 'sigv4a_signing_region_set ' ,
1325
- '' ,
1326
- 'string '
1327
- );
1328
- }
1329
-
1330
1324
public static function _apply_region ($ value , array &$ args )
1331
1325
{
1332
1326
if (empty ($ value )) {
@@ -1335,11 +1329,6 @@ public static function _apply_region($value, array &$args)
1335
1329
$ args ['region ' ] = $ value ;
1336
1330
}
1337
1331
1338
- public static function _default_region (&$ args )
1339
- {
1340
- return ConfigurationResolver::resolve ('region ' , '' , 'string ' );
1341
- }
1342
-
1343
1332
public static function _missing_region (array $ args )
1344
1333
{
1345
1334
$ service = $ args ['service ' ] ?? '' ;
@@ -1356,6 +1345,35 @@ public static function _missing_region(array $args)
1356
1345
throw new IAE ($ msg );
1357
1346
}
1358
1347
1348
+ /**
1349
+ * Resolves a value from env or config.
1350
+ *
1351
+ * @param $key
1352
+ * @param $expectedType
1353
+ * @param $args
1354
+ *
1355
+ * @return mixed|string
1356
+ */
1357
+ private static function _resolve_from_env_ini (
1358
+ string $ key ,
1359
+ string $ expectedType ,
1360
+ array $ args
1361
+ ) {
1362
+ static $ typeDefaultMap = [
1363
+ 'int ' => 0 ,
1364
+ 'bool ' => false ,
1365
+ 'boolean ' => false ,
1366
+ 'string ' => '' ,
1367
+ ];
1368
+
1369
+ return ConfigurationResolver::resolve (
1370
+ $ key ,
1371
+ $ typeDefaultMap [$ expectedType ] ?? '' ,
1372
+ $ expectedType ,
1373
+ $ args
1374
+ );
1375
+ }
1376
+
1359
1377
/**
1360
1378
* Extracts client options for the endpoint provider to its own array
1361
1379
*
0 commit comments