From bd544e21f1f683781f4fa4a2f3e674ea483c4386 Mon Sep 17 00:00:00 2001 From: Sean O'Brien Date: Thu, 11 Jul 2024 14:12:29 -0400 Subject: [PATCH 1/2] feat: add deprecation notice --- .changes/nextrelease/deprecation-warning.json | 7 +++ Makefile | 2 +- src/ClientResolver.php | 52 ++++++++++++++++++- tests/ClientResolverTest.php | 19 +++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 .changes/nextrelease/deprecation-warning.json diff --git a/.changes/nextrelease/deprecation-warning.json b/.changes/nextrelease/deprecation-warning.json new file mode 100644 index 0000000000..8bbef10b44 --- /dev/null +++ b/.changes/nextrelease/deprecation-warning.json @@ -0,0 +1,7 @@ +[ + { + "type": "feature", + "category": "", + "description": "Adds notice for the upcoming deprecation of PHP versions 8.0.x and below." + } +] diff --git a/Makefile b/Makefile index 8fb53e7392..32c6ea16ac 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ clear-cache: php build/aws-clear-cache.php test: - @AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar AWS_CSM_ENABLED=false AWS_REGION= AWS_ENDPOINT_URL= \ + @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 \ vendor/bin/phpunit --testsuite=unit $(TEST) test-phar: package diff --git a/src/ClientResolver.php b/src/ClientResolver.php index a99442c2f3..82c9d5b3b5 100644 --- a/src/ClientResolver.php +++ b/src/ClientResolver.php @@ -308,6 +308,13 @@ class ClientResolver '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.', 'default' => true, ], + 'suppress_php_deprecation_warning' => [ + 'type' => 'value', + 'valid' => ['bool'], + '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.', + 'default' => false, + 'fn' => [__CLASS__, '_apply_suppress_php_deprecation_warning'] + ] ]; /** @@ -1192,6 +1199,28 @@ public static function _apply_ignore_configured_endpoint_urls($value, array &$ar $args['config']['ignore_configured_endpoint_urls'] = $value; } + public static function _apply_suppress_php_deprecation_warning($value, &$args) + { + if ($value) { + $args['suppress_php_deprecation_warning'] = true; + } elseif (!empty(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING"))) { + $args['suppress_php_deprecation_warning'] + = \Aws\boolean_value(getenv("AWS_SUPPRESS_PHP_DEPRECATION_WARNING")); + } elseif (!empty($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) { + $args['suppress_php_deprecation_warning'] = + \Aws\boolean_value($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]); + } elseif (!empty($_ENV["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"])) { + $args['suppress_php_deprecation_warning'] = + \Aws\boolean_value($_SERVER["AWS_SUPPRESS_PHP_DEPRECATION_WARNING"]); + } + + if ($args['suppress_php_deprecation_warning'] === false + && PHP_VERSION_ID < 80100 + ) { + self::emitDeprecationWarning(); + } + } + public static function _default_ignore_configured_endpoint_urls(array &$args) { return ConfigurationResolver::resolve( @@ -1334,7 +1363,8 @@ private function _apply_client_context_params(array $args) } } - private static function isValidService($service) { + private static function isValidService($service) + { if (is_null($service)) { return false; } @@ -1342,7 +1372,8 @@ private static function isValidService($service) { return isset($services[$service]); } - private static function isValidApiVersion($service, $apiVersion) { + private static function isValidApiVersion($service, $apiVersion) + { if (is_null($apiVersion)) { return false; } @@ -1350,4 +1381,21 @@ private static function isValidApiVersion($service, $apiVersion) { __DIR__ . "/data/{$service}/$apiVersion" ); } + + private static function emitDeprecationWarning() + { + $phpVersionString = phpversion(); + trigger_error( + "This installation of the SDK is using PHP version" + . " {$phpVersionString}, which will be deprecated on January" + . " 13th, 2025.\nPlease upgrade your PHP version to a minimum of" + . " 8.1.x to continue receiving updates for the AWS" + . " SDK for PHP.\nTo disable this warning, set" + . " suppress_php_deprecation_warning to true on the client constructor" + . " or set the environment variable AWS_SUPPRESS_PHP_DEPRECATION_WARNING" + . " to true.\nMore information can be found at: " + . "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", + E_USER_WARNING + ); + } } diff --git a/tests/ClientResolverTest.php b/tests/ClientResolverTest.php index dfb114398f..aa15a48884 100644 --- a/tests/ClientResolverTest.php +++ b/tests/ClientResolverTest.php @@ -1677,4 +1677,23 @@ public function testAppliesAuthSchemeResolver() $conf['auth_scheme_resolver'] ); } + + public function testEmitsDeprecationWarning() + { + if (PHP_VERSION_ID >= 80100) { + $this->markTestSkipped(); + } + + putenv('AWS_SUPPRESS_PHP_DEPRECATION_WARNING=false'); + $this->expectWarning(); + $this->expectWarningMessage('This installation of the SDK is using PHP version'); + + $r = new ClientResolver(ClientResolver::getDefaultArguments()); + + try { + $r->resolve(['service' => 'sqs', 'region' => 'x'], new HandlerList()); + } finally { + putenv('AWS_SUPPRESS_PHP_DEPRECATION_WARNING=true'); + } + } } From e122eaaf2ecf22456cf5a9caf201d7e614007efc Mon Sep 17 00:00:00 2001 From: Sean O'Brien Date: Wed, 17 Jul 2024 16:36:16 -0400 Subject: [PATCH 2/2] mend --- src/AwsClient.php | 5 +++++ tests/AwsClientTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/AwsClient.php b/src/AwsClient.php index 3b36d38fac..33f9bc3521 100644 --- a/src/AwsClient.php +++ b/src/AwsClient.php @@ -648,6 +648,11 @@ protected function isUseEndpointV2() } public static function emitDeprecationWarning() { + trigger_error( + "This method is deprecated. It will be removed in an upcoming release." + , E_USER_DEPRECATED + ); + $phpVersion = PHP_VERSION_ID; if ($phpVersion < 70205) { $phpVersionString = phpversion(); diff --git a/tests/AwsClientTest.php b/tests/AwsClientTest.php index 66fba3142d..a3b2c9960c 100644 --- a/tests/AwsClientTest.php +++ b/tests/AwsClientTest.php @@ -765,6 +765,16 @@ public function testAppliesConfiguredSignatureVersionViaClientConfig() { $client->foo(); } + public function testCallingEmitDeprecationWarningEmitsDeprecationWarning() + { + $this->expectDeprecation(); + $this->expectDeprecationMessage( + "This method is deprecated. It will be removed in an upcoming release." + ); + $client = $this->createClient(); + $client::emitDeprecationWarning(); + } + private function createHttpsEndpointClient(array $service = [], array $config = []) { $apiProvider = function () use ($service) {