Skip to content

Commit 6f849d2

Browse files
authored
Merge pull request #1096 from clue-labs/php8.2
Support PHP 8.2 and work around reporting dynamic properties
2 parents 31040b8 + 6fe567e commit 6f849d2

18 files changed

Lines changed: 57 additions & 25 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- "7.4"
2323
- "8.0"
2424
- "8.1"
25+
- "8.2"
2526
dependencies:
2627
- "highest"
2728
include:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ composer require cboden/ratchet:^0.4.4
101101
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
102102

103103
This project aims to run on any platform and thus does not require any PHP
104-
extensions and supports running on legacy PHP 5.4 through PHP 8.1+ with limited support for PHP 8.2+.
104+
extensions and supports running on legacy PHP 5.4 through PHP 8.2+ with limited support for newer PHP.
105105
It's *highly recommended to use the latest supported PHP version* for this project.
106106

107107
See above note about [Reviving Ratchet](#reviving-ratchet) for newer PHP support.

phpunit.xml.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
66
bootstrap="tests/bootstrap.php"
77
cacheResult="false"
8-
colors="true">
8+
colors="true"
9+
convertDeprecationsToExceptions="true">
910
<testsuites>
1011
<testsuite name="Ratchet test suite">
1112
<directory>./tests/unit/</directory>
@@ -16,4 +17,7 @@
1617
<directory>./src/</directory>
1718
</include>
1819
</coverage>
20+
<php>
21+
<ini name="error_reporting" value="-1" />
22+
</php>
1923
</phpunit>

phpunit.xml.legacy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
<directory>./src/</directory>
1616
</whitelist>
1717
</filter>
18+
<php>
19+
<ini name="error_reporting" value="-1" />
20+
</php>
1821
</phpunit>

src/Ratchet/AbstractConnectionDecorator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
/**
55
* Wraps ConnectionInterface objects via the decorator pattern but allows
66
* parameters to bubble through with magic methods
7+
*
8+
* Note that this instance does not use the `#[\AllowDynamicProperties]`
9+
* attribute for PHP 8.2+ compatibility as any properties added to this class
10+
* will be forwarded to the wrapped instance.
11+
*
712
* @todo It sure would be nice if I could make most of this a trait...
813
*/
914
abstract class AbstractConnectionDecorator implements ConnectionInterface {

src/Ratchet/ConnectionInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
/**
1111
* A proxy object representing a connection to the application
1212
* This acts as a container to store data (in memory) about the connection
13+
*
14+
* Note that Ratchet makes heavy use of the decorator pattern and dynamic
15+
* properties. This means any object that implements this interface may not
16+
* have the same methods or properties as the ones in this interface.
17+
* Implementations of this interface may have to use the `#[\AllowDynamicProperties]`
18+
* attribute to allow dynamic properties on PHP 8.2+.
1319
*/
1420
interface ConnectionInterface {
1521
/**

src/Ratchet/Server/IoConnection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
namespace Ratchet\Server;
33
use Ratchet\ConnectionInterface;
4-
use React\Socket\ConnectionInterface as ReactConn;
4+
use React\Socket\ConnectionInterface as SocketConnection;
55

66
/**
77
* {@inheritdoc}
88
*/
9+
#[\AllowDynamicProperties]
910
class IoConnection implements ConnectionInterface {
1011
/**
1112
* @var \React\Socket\ConnectionInterface
@@ -16,7 +17,7 @@ class IoConnection implements ConnectionInterface {
1617
/**
1718
* @param \React\Socket\ConnectionInterface $conn
1819
*/
19-
public function __construct(ReactConn $conn) {
20+
public function __construct(SocketConnection $conn) {
2021
$this->conn = $conn;
2122
}
2223

src/Ratchet/Server/IoServer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Ratchet\Server;
33
use Ratchet\MessageComponentInterface;
44
use React\EventLoop\LoopInterface;
5+
use React\Socket\ConnectionInterface as SocketConnection;
56
use React\Socket\ServerInterface;
67
use React\EventLoop\Factory as LoopFactory;
78
use React\Socket\Server as Reactor;
@@ -79,8 +80,13 @@ public function run() {
7980
* Triggered when a new connection is received from React
8081
* @param \React\Socket\ConnectionInterface $conn
8182
*/
82-
public function handleConnect($conn) {
83+
public function handleConnect(SocketConnection $conn) {
84+
// assign dynamic `$decor` property used by Ratchet without raising notice on PHP 8.2+
85+
// need this hack because we can't use `#[\AllowDynamicProperties]` on vendor code
86+
set_error_handler(function () { }, E_DEPRECATED);
8387
$conn->decor = new IoConnection($conn);
88+
restore_error_handler();
89+
8490
$conn->decor->resourceId = (int)$conn->stream;
8591

8692
$uri = $conn->getRemoteAddress();

tests/helpers/Ratchet/AbstractMessageComponentTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function setUpConnection() {
1919
$this->_app = $this->getMockBuilder($this->getComponentClassString())->getMock();
2020
$decorator = $this->getDecoratorClassString();
2121
$this->_serv = new $decorator($this->_app);
22-
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
22+
$this->_conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
2323

2424
$this->doOpen($this->_conn);
2525
}
@@ -34,7 +34,7 @@ public function isExpectedConnection() {
3434

3535
public function testOpen() {
3636
$this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
37-
$this->doOpen($this->getMockBuilder('Ratchet\ConnectionInterface')->getMock());
37+
$this->doOpen($this->getMockBuilder('Ratchet\Mock\Connection')->getMock());
3838
}
3939

4040
public function testOnClose() {

tests/helpers/Ratchet/Mock/Connection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Ratchet\Mock;
33
use Ratchet\ConnectionInterface;
44

5+
#[\AllowDynamicProperties]
56
class Connection implements ConnectionInterface {
67
public $last = array(
78
'send' => ''

0 commit comments

Comments
 (0)