-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PHP >= 8 support + updated tests and workflow. #1014
base: master
Are you sure you want to change the base?
Changes from all commits
6bc3958
b7aa6a5
78c0e0e
8e6acea
84b3fe5
5c39aec
5961041
1022815
62da503
b45aa35
addf94f
67f655b
6b88bc1
6a6b3f9
95e07c0
cb3f72b
bd33ac5
b58f1fa
3020d28
d14857d
56b8cec
cd914b4
129c47e
4110b83
158e944
6bddff9
2112cd0
572f3d0
be721b4
a7ffaa1
e9d5aee
cf012e1
353284d
6bfc3fb
e2ab1f2
ee9e32f
3eb5ebd
1b8afc5
203b09f
f03ed0d
6fa228f
672cac4
b7de821
5bbdaa3
51f73d3
3953527
eba9487
f662dfd
f75aa4b
2ae3ea8
3c0701e
2578564
b70073f
12a1a13
3e7f7f1
2904585
c62998b
f3559e9
cd493aa
8f4a6dd
6590803
836a02c
ccfaf84
533b273
3e8e3c2
755977d
003d972
634792a
d13402f
136f614
7c28424
54c0aef
e7e7e32
dc69b28
6d2f6a2
bc519b9
56a7c2b
4311014
be5e072
688b810
dc5edca
30959f5
0505b4a
4982587
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ phpunit.xml | |
reports | ||
sandbox | ||
vendor | ||
composer.lock | ||
composer.lock | ||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
namespace Ratchet\Server; | ||
use Ratchet\MessageComponentInterface; | ||
use Ratchet\Traits\DynamicPropertiesTrait; | ||
use React\EventLoop\LoopInterface; | ||
use React\Socket\ServerInterface; | ||
use React\EventLoop\Factory as LoopFactory; | ||
|
@@ -12,6 +13,8 @@ | |
* Events are delegated through this to attached applications | ||
*/ | ||
class IoServer { | ||
use DynamicPropertiesTrait; | ||
|
||
/** | ||
* @var \React\EventLoop\LoopInterface | ||
*/ | ||
|
@@ -80,61 +83,61 @@ public function run() { | |
* @param \React\Socket\ConnectionInterface $conn | ||
*/ | ||
public function handleConnect($conn) { | ||
$conn->decor = new IoConnection($conn); | ||
$conn->decor->resourceId = (int)$conn->stream; | ||
$io_conn = new IoConnection($conn); | ||
$io_conn->resourceId = (int)$conn->stream; | ||
|
||
$uri = $conn->getRemoteAddress(); | ||
$conn->decor->remoteAddress = trim( | ||
$io_conn->remoteAddress = trim( | ||
parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST), | ||
'[]' | ||
); | ||
|
||
$this->app->onOpen($conn->decor); | ||
$this->app->onOpen($io_conn); | ||
|
||
$conn->on('data', function ($data) use ($conn) { | ||
$this->handleData($data, $conn); | ||
$conn->on('data', function ($data) use ($io_conn) { | ||
$this->handleData($data, $io_conn); | ||
}); | ||
$conn->on('close', function () use ($conn) { | ||
$this->handleEnd($conn); | ||
$conn->on('close', function () use ($io_conn) { | ||
$this->handleEnd($io_conn); | ||
}); | ||
$conn->on('error', function (\Exception $e) use ($conn) { | ||
$this->handleError($e, $conn); | ||
$conn->on('error', function (\Exception $e) use ($io_conn) { | ||
$this->handleError($e, $io_conn); | ||
}); | ||
} | ||
|
||
/** | ||
* Data has been received from React | ||
* @param string $data | ||
* @param \React\Socket\ConnectionInterface $conn | ||
* @param \Ratchet\ConnectionInterface $io_conn | ||
*/ | ||
public function handleData($data, $conn) { | ||
public function handleData($data, $io_conn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the parameter there and in the other methods is a breaking change, because IoServer can be extended There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, this a breaking change, however it was done because \React\Socket\ConnectionInterface doesn't actually have the decor property previously being used to pass the connection around and PHP 8 deprecated dymanic property creation. |
||
try { | ||
$this->app->onMessage($conn->decor, $data); | ||
$this->app->onMessage($io_conn, $data); | ||
} catch (\Exception $e) { | ||
$this->handleError($e, $conn); | ||
$this->handleError($e, $io_conn); | ||
} | ||
} | ||
|
||
/** | ||
* A connection has been closed by React | ||
* @param \React\Socket\ConnectionInterface $conn | ||
* @param \Ratchet\ConnectionInterface $io_conn | ||
*/ | ||
public function handleEnd($conn) { | ||
public function handleEnd($io_conn) { | ||
try { | ||
$this->app->onClose($conn->decor); | ||
$this->app->onClose($io_conn); | ||
} catch (\Exception $e) { | ||
$this->handleError($e, $conn); | ||
$this->handleError($e, $io_conn); | ||
} | ||
|
||
unset($conn->decor); | ||
unset($io_conn); | ||
} | ||
|
||
/** | ||
* An error has occurred, let the listening application know | ||
* @param \Exception $e | ||
* @param \React\Socket\ConnectionInterface $conn | ||
* @param \Ratchet\ConnectionInterface $io_conn | ||
*/ | ||
public function handleError(\Exception $e, $conn) { | ||
$this->app->onError($conn->decor, $e); | ||
public function handleError(\Exception $e, $io_conn) { | ||
$this->app->onError($io_conn, $e); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
namespace Ratchet\Session\Storage\Proxy; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; | ||
|
||
class VirtualProxy extends SessionHandlerProxy { | ||
/** | ||
* @var string | ||
*/ | ||
protected $_sessionId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_sessionName; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(\SessionHandlerInterface $handler) { | ||
parent::__construct($handler); | ||
|
||
$this->saveHandlerName = 'user'; | ||
$this->_sessionName = ini_get('session.name'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getId(): string { | ||
return $this->_sessionId; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setId($id) { | ||
$this->_sessionId = $id; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string { | ||
return $this->_sessionName; | ||
} | ||
|
||
/** | ||
* DO NOT CALL THIS METHOD | ||
* @internal | ||
*/ | ||
public function setName($name) { | ||
throw new \RuntimeException("Can not change session name in VirtualProxy"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing
$conn->decor
should still be left to avoid a breaking changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decor is not a property of \React\Socket\ConnectionInterface so can't be left in because php 8 deprecated dynamic property creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe we also make a PR to reactphp/socket to add #[AllowDynamicProperties] to the interface https://github.com/reactphp/socket/blob/3.x/src/ConnectorInterface.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we simply use spl storage locally in IoServer to store the decor and retrieve it when needed