Skip to content

Commit c6450f5

Browse files
authored
Merge pull request #1099 from clue-labs/php8.4
Support PHP 8.4 and work around reporting implicitly nullable types
2 parents a0d98d3 + d39e273 commit c6450f5

14 files changed

Lines changed: 73 additions & 54 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- "8.1"
2525
- "8.2"
2626
- "8.3"
27+
- "8.4"
2728
dependencies:
2829
- "highest"
2930
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.3+ with limited support for newer PHP.
104+
extensions and supports running on legacy PHP 5.4 through current PHP 8+.
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.

src/Ratchet/App.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ class App {
5757
protected $_routeCounter = 0;
5858

5959
/**
60-
* @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
61-
* @param int $port Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
62-
* @param string $address IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
63-
* @param LoopInterface $loop Specific React\EventLoop to bind the application to. null will create one for you.
64-
* @param array $context
60+
* @param string $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
61+
* @param int $port Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
62+
* @param string $address IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
63+
* @param ?LoopInterface $loop Specific React\EventLoop to bind the application to. null will create one for you.
64+
* @param array $context
6565
*/
66-
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null, $context = array()) {
66+
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', $loop = null, $context = array()) {
6767
if (extension_loaded('xdebug') && getenv('RATCHET_DISABLE_XDEBUG_WARN') === false) {
6868
trigger_error('XDebug extension detected. Remember to disable this if performance testing or going live!', E_USER_WARNING);
6969
}
70+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
71+
throw new \InvalidArgumentException('Argument #4 ($loop) expected null|React\EventLoop\LoopInterface');
72+
}
7073

7174
if (null === $loop) {
7275
$loop = LoopFactory::create();

src/Ratchet/Http/HttpServerInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ interface HttpServerInterface extends MessageComponentInterface {
1010
* @param \Psr\Http\Message\RequestInterface $request null is default because PHP won't let me overload; don't pass null!!!
1111
* @throws \UnexpectedValueException if a RequestInterface is not passed
1212
*/
13-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null);
13+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null); /*
14+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null); /**/
1415
}

src/Ratchet/Http/NoOpHttpServerController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use Psr\Http\Message\RequestInterface;
55

66
class NoOpHttpServerController implements HttpServerInterface {
7-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
7+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
8+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
89
}
910

1011
public function onMessage(ConnectionInterface $from, $msg) {

src/Ratchet/Http/OriginCheck.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function __construct(MessageComponentInterface $component, array $allowed
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
34+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
35+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
3536
$header = (string)$request->getHeader('Origin')[0];
3637
$origin = parse_url($header, PHP_URL_HOST) ?: $header;
3738

src/Ratchet/Http/Router.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function __construct(UrlMatcherInterface $matcher) {
2626
* {@inheritdoc}
2727
* @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
2828
*/
29-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
29+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
30+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
3031
if (null === $request) {
3132
throw new \UnexpectedValueException('$request can not be null');
3233
}

src/Ratchet/Server/IoServer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class IoServer {
3434
* @param \React\Socket\ServerInterface $socket The React socket server to run the Ratchet application off of
3535
* @param \React\EventLoop\LoopInterface|null $loop The React looper to run the Ratchet application off of
3636
*/
37-
public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop = null) {
37+
public function __construct(MessageComponentInterface $app, ServerInterface $socket, $loop = null) {
38+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
39+
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
40+
}
41+
3842
if (false === strpos(PHP_VERSION, "hiphop")) {
3943
gc_enable();
4044
}

src/Ratchet/Session/SessionProvider.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ class SessionProvider implements HttpServerInterface {
3838
protected $_serializer;
3939

4040
/**
41-
* @param \Ratchet\Http\HttpServerInterface $app
42-
* @param \SessionHandlerInterface $handler
43-
* @param array $options
44-
* @param \Ratchet\Session\Serialize\HandlerInterface $serializer
41+
* @param \Ratchet\Http\HttpServerInterface $app
42+
* @param \SessionHandlerInterface $handler
43+
* @param array $options
44+
* @param ?\Ratchet\Session\Serialize\HandlerInterface $serializer
4545
* @throws \RuntimeException
4646
*/
47-
public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) {
47+
public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, array $options = array(), $serializer = null) {
48+
if ($serializer !== null && !$serializer instanceof HandlerInterface) { // manual type check to support legacy PHP < 7.1
49+
throw new \InvalidArgumentException('Argument #4 ($serializer) expected null|Ratchet\Session\Serialize\HandlerInterface');
50+
}
4851
$this->_app = $app;
4952
$this->_handler = $handler;
5053
$this->_null = new NullSessionHandler;
@@ -70,7 +73,8 @@ public function __construct(HttpServerInterface $app, \SessionHandlerInterface $
7073
/**
7174
* {@inheritdoc}
7275
*/
73-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
76+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
77+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
7478
$sessionName = ini_get('session.name');
7579

7680
$id = array_reduce($request->getHeader('Cookie'), function($accumulator, $cookie) use ($sessionName) {

src/Ratchet/WebSocket/WsServer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public function __construct(ComponentInterface $component) {
104104
/**
105105
* {@inheritdoc}
106106
*/
107-
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
107+
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
108+
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
108109
if (null === $request) {
109110
throw new \UnexpectedValueException('$request can not be null');
110111
}

0 commit comments

Comments
 (0)