Skip to content

Commit ba1f0b7

Browse files
authored
feat: add deprecation notice (#2951)
1 parent eaa1f85 commit ba1f0b7

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"type": "feature",
4+
"category": "",
5+
"description": "Adds notice for the upcoming deprecation of PHP versions 8.0.x and below."
6+
}
7+
]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ clear-cache:
2424
php build/aws-clear-cache.php
2525

2626
test:
27-
@AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar AWS_CSM_ENABLED=false AWS_REGION= AWS_ENDPOINT_URL= \
27+
@AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar AWS_CSM_ENABLED=false AWS_REGION= AWS_ENDPOINT_URL= AWS_SUPPRESS_PHP_DEPRECATION_WARNING=true \
2828
vendor/bin/phpunit --testsuite=unit $(TEST)
2929

3030
test-phar: package

src/AwsClient.php

+5
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,11 @@ protected function isUseEndpointV2()
684684
}
685685

686686
public static function emitDeprecationWarning() {
687+
trigger_error(
688+
"This method is deprecated. It will be removed in an upcoming release."
689+
, E_USER_DEPRECATED
690+
);
691+
687692
$phpVersion = PHP_VERSION_ID;
688693
if ($phpVersion < 70205) {
689694
$phpVersionString = phpversion();

src/ClientResolver.php

+50-2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ class ClientResolver
308308
'doc' => 'Set to false to disable checking for shared aws config files usually located in \'~/.aws/config\' and \'~/.aws/credentials\'. This will be ignored if you set the \'profile\' setting.',
309309
'default' => true,
310310
],
311+
'suppress_php_deprecation_warning' => [
312+
'type' => 'value',
313+
'valid' => ['bool'],
314+
'doc' => 'Set to true to suppress PHP runtime deprecation warnings. The current deprecation campaign is PHP versions 8.0.x and below, taking effect on 1/13/2025.',
315+
'default' => false,
316+
'fn' => [__CLASS__, '_apply_suppress_php_deprecation_warning']
317+
],
311318
'account_id_endpoint_mode' => [
312319
'type' => 'value',
313320
'valid' => ['string'],
@@ -1230,6 +1237,28 @@ public static function _apply_ignore_configured_endpoint_urls($value, array &$ar
12301237
$args['config']['ignore_configured_endpoint_urls'] = $value;
12311238
}
12321239

1240+
public static function _apply_suppress_php_deprecation_warning($value, &$args)
1241+
{
1242+
if ($value) {
1243+
$args['suppress_php_deprecation_warning'] = true;
1244+
} elseif (!empty(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING"))) {
1245+
$args['suppress_php_deprecation_warning']
1246+
= \Aws\boolean_value(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING"));
1247+
} elseif (!empty($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) {
1248+
$args['suppress_php_deprecation_warning'] =
1249+
\Aws\boolean_value($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]);
1250+
} elseif (!empty($_ENV["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) {
1251+
$args['suppress_php_deprecation_warning'] =
1252+
\Aws\boolean_value($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]);
1253+
}
1254+
1255+
if ($args['suppress_php_deprecation_warning'] === false
1256+
&& PHP_VERSION_ID < 80100
1257+
) {
1258+
self::emitDeprecationWarning();
1259+
}
1260+
}
1261+
12331262
public static function _default_ignore_configured_endpoint_urls(array &$args)
12341263
{
12351264
return ConfigurationResolver::resolve(
@@ -1392,20 +1421,39 @@ private function _apply_client_context_params(array $args)
13921421
}
13931422
}
13941423

1395-
private static function isValidService($service) {
1424+
private static function isValidService($service)
1425+
{
13961426
if (is_null($service)) {
13971427
return false;
13981428
}
13991429
$services = \Aws\manifest();
14001430
return isset($services[$service]);
14011431
}
14021432

1403-
private static function isValidApiVersion($service, $apiVersion) {
1433+
private static function isValidApiVersion($service, $apiVersion)
1434+
{
14041435
if (is_null($apiVersion)) {
14051436
return false;
14061437
}
14071438
return is_dir(
14081439
__DIR__ . "/data/{$service}/$apiVersion"
14091440
);
14101441
}
1442+
1443+
private static function emitDeprecationWarning()
1444+
{
1445+
$phpVersionString = phpversion();
1446+
trigger_error(
1447+
"This installation of the SDK is using PHP version"
1448+
. " {$phpVersionString}, which will be deprecated on January"
1449+
. " 13th, 2025.\nPlease upgrade your PHP version to a minimum of"
1450+
. " 8.1.x to continue receiving updates for the AWS"
1451+
. " SDK for PHP.\nTo disable this warning, set"
1452+
. " suppress_php_deprecation_warning to true on the client constructor"
1453+
. " or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING"
1454+
. " to true.\nMore information can be found at: "
1455+
. "https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-php-runtimes-8-0-x-and-below-in-the-aws-sdk-for-php/\n",
1456+
E_USER_WARNING
1457+
);
1458+
}
14111459
}

tests/AwsClientTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,17 @@ public function testAppliesConfiguredSignatureVersionViaClientConfig() {
767767
$client->foo();
768768
}
769769

770+
771+
public function testCallingEmitDeprecationWarningEmitsDeprecationWarning()
772+
{
773+
$this->expectDeprecation();
774+
$this->expectDeprecationMessage(
775+
"This method is deprecated. It will be removed in an upcoming release."
776+
);
777+
$client = $this->createClient();
778+
$client::emitDeprecationWarning();
779+
}
780+
770781
/**
771782
* @dataProvider signingRegionSetProvider
772783
* @runInSeparateProcess
@@ -833,7 +844,6 @@ public function testSigningRegionSetResolution(
833844
}
834845

835846
putenv('AWS_SIGV4A_SIGNING_REGION_SET=');
836-
837847
}
838848

839849
public function signingRegionSetProvider()

tests/ClientResolverTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -1677,4 +1677,23 @@ public function testAppliesAuthSchemeResolver()
16771677
$conf['auth_scheme_resolver']
16781678
);
16791679
}
1680+
1681+
public function testEmitsDeprecationWarning()
1682+
{
1683+
if (PHP_VERSION_ID >= 80100) {
1684+
$this->markTestSkipped();
1685+
}
1686+
1687+
putenv('AWS_SUPPRESS_PHP_DEPRECATION_WARNING=false');
1688+
$this->expectWarning();
1689+
$this->expectWarningMessage('This installation of the SDK is using PHP version');
1690+
1691+
$r = new ClientResolver(ClientResolver::getDefaultArguments());
1692+
1693+
try {
1694+
$r->resolve(['service' => 'sqs', 'region' => 'x'], new HandlerList());
1695+
} finally {
1696+
putenv('AWS_SUPPRESS_PHP_DEPRECATION_WARNING=true');
1697+
}
1698+
}
16801699
}

0 commit comments

Comments
 (0)