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 *