From 6f1d3f62cfb5dc126d6f1c52c002fa63a64e9245 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 13 Nov 2026 00:14:30 +0100 Subject: [PATCH] Deprecate the socket transport The socket transport implements HTTP/1.x by hand: it cannot be configured for TLS, does not support proxies and does not decode chunked responses. The cURL and stream transports cover every environment it is used in. Mark it deprecated and trigger a deprecation when it is created, ahead of its removal in 5.0. This adds symfony/deprecation-contracts as a dependency, as in the other framework packages. Co-Authored-By: Claude Opus 5.5 --- Tests/Transport/SocketDeprecationTest.php | 47 +++++++++++++++++++++++ composer.json | 3 +- docs/classes/TransportInterface.md | 2 +- src/Transport/Socket.php | 23 ++++++++++- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 Tests/Transport/SocketDeprecationTest.php diff --git a/Tests/Transport/SocketDeprecationTest.php b/Tests/Transport/SocketDeprecationTest.php new file mode 100644 index 00000000..2a89c8d2 --- /dev/null +++ b/Tests/Transport/SocketDeprecationTest.php @@ -0,0 +1,47 @@ +markTestSkipped('The socket transport is not supported in this environment.'); + } + + $deprecations = []; + + set_error_handler( + static function (int $severity, string $message) use (&$deprecations): bool { + if ($severity === E_USER_DEPRECATED) { + $deprecations[] = $message; + } + + return true; + } + ); + + try { + new Socket([]); + } finally { + restore_error_handler(); + } + + $this->assertCount(1, $deprecations); + $this->assertStringContainsString('transport is deprecated and will be removed in 5.0', $deprecations[0]); + } +} diff --git a/composer.json b/composer.json index 8572b90d..dbbac686 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "psr/http-message": "^2.0", "joomla/uri": "^4.0", "composer/ca-bundle": "^1.3.5", - "laminas/laminas-diactoros": "^3.6.0" + "laminas/laminas-diactoros": "^3.6.0", + "symfony/deprecation-contracts": "^2|^3" }, "require-dev": { "joomla/test": "^4.0", diff --git a/docs/classes/TransportInterface.md b/docs/classes/TransportInterface.md index ffb364a5..74a1dbab 100644 --- a/docs/classes/TransportInterface.md +++ b/docs/classes/TransportInterface.md @@ -35,7 +35,7 @@ directly. |---|---|---| | `Transport\Curl` | `ext-curl` loaded | The default when available | | `Transport\Stream` | `allow_url_fopen` enabled | Configurable TLS via a stream context | -| `Transport\Socket` | `fsockopen()` exists | Cannot be configured for TLS — see below | +| `Transport\Socket` | `fsockopen()` exists | **Deprecated**, will be removed in 5.0; creating it triggers a deprecation notice. Cannot be configured for TLS — see below | `HttpFactory` picks one for you: diff --git a/src/Transport/Socket.php b/src/Transport/Socket.php index 9aedd4c8..710ed7a4 100644 --- a/src/Transport/Socket.php +++ b/src/Transport/Socket.php @@ -19,7 +19,8 @@ /** * HTTP transport class for using sockets directly. * - * @since 1.0 + * @since 1.0 + * @deprecated 5.0 Use the Curl or Stream transport instead; this transport will be removed. */ class Socket extends AbstractTransport { @@ -277,6 +278,26 @@ protected function connect(UriInterface $uri, $timeout = null) return $this->connections[$key]; } + /** + * Constructor. + * + * @param array|\ArrayAccess $options Client options array. + * + * @since __DEPLOY_VERSION__ + * @throws \RuntimeException + */ + public function __construct($options = []) + { + trigger_deprecation( + 'joomla/http', + '__DEPLOY_VERSION__', + 'The %s transport is deprecated and will be removed in 5.0, use the Curl or Stream transport instead.', + self::class + ); + + parent::__construct($options); + } + /** * Method to check if http transport socket available for use *