Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Tests/Transport/SocketDeprecationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @copyright Copyright (C) 2005 - 2026 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Http\Tests\Transport;

use Joomla\Http\Transport\Socket;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* Test class for the deprecation of Joomla\Http\Transport\Socket.
*/
#[CoversClass(Socket::class)]
class SocketDeprecationTest extends TestCase
{
public function testCreatingTheSocketTransportTriggersADeprecation(): void
{
if (!Socket::isSupported()) {
$this->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]);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/TransportInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
23 changes: 22 additions & 1 deletion src/Transport/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
*
Expand Down
Loading