Update on null args
Some checks are pending
CI / PHPUnit (highest, 5.4) (push) Waiting to run
CI / PHPUnit (highest, 5.5) (push) Waiting to run
CI / PHPUnit (highest, 5.6) (push) Waiting to run
CI / PHPUnit (highest, 7.0) (push) Waiting to run
CI / PHPUnit (highest, 7.1) (push) Waiting to run
CI / PHPUnit (highest, 7.2) (push) Waiting to run
CI / PHPUnit (highest, 7.3) (push) Waiting to run
CI / PHPUnit (highest, 7.4) (push) Waiting to run
CI / PHPUnit (lowest, 5.4) (push) Waiting to run

This commit is contained in:
Mohamad Faeez 2025-04-09 14:33:22 +08:00
parent e70d9d7a96
commit 11a39c8e46
7 changed files with 15 additions and 8 deletions

View File

@ -63,7 +63,12 @@ class App {
* @param LoopInterface $loop Specific React\EventLoop to bind the application to. null will create one for you.
* @param array $context
*/
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null, $context = array()) {
public function __construct(?string $httpHost = null, ?int $port = null, ?string $address = null, ?LoopInterface $loop = null, ?array $context = null) {
if ($httpHost == null) $httpHost = 'localhost';
if ($port == null) $port = 80;
if ($address == null) $address = '127.0.0.1';
if ($context == null) $context = array();
if (extension_loaded('xdebug') && getenv('RATCHET_DISABLE_XDEBUG_WARN') === false) {
trigger_error('XDebug extension detected. Remember to disable this if performance testing or going live!', E_USER_WARNING);
}

View File

@ -10,5 +10,5 @@ interface HttpServerInterface extends MessageComponentInterface {
* @param \Psr\Http\Message\RequestInterface $request null is default because PHP won't let me overload; don't pass null!!!
* @throws \UnexpectedValueException if a RequestInterface is not passed
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null);
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null);
}

View File

@ -4,7 +4,7 @@ use Ratchet\ConnectionInterface;
use Psr\Http\Message\RequestInterface;
class NoOpHttpServerController implements HttpServerInterface {
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) {
}
public function onMessage(ConnectionInterface $from, $msg) {

View File

@ -31,7 +31,7 @@ class OriginCheck implements HttpServerInterface {
/**
* {@inheritdoc}
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) {
$header = (string)$request->getHeader('Origin')[0];
$origin = parse_url($header, PHP_URL_HOST) ?: $header;

View File

@ -26,7 +26,7 @@ class Router implements HttpServerInterface {
* {@inheritdoc}
* @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) {
if (null === $request) {
throw new \UnexpectedValueException('$request can not be null');
}

View File

@ -44,7 +44,9 @@ class SessionProvider implements HttpServerInterface {
* @param \Ratchet\Session\Serialize\HandlerInterface $serializer
* @throws \RuntimeException
*/
public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) {
public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, ?array $options = null, ?HandlerInterface $serializer = null) {
if ($options == null) $options = array();
$this->_app = $app;
$this->_handler = $handler;
$this->_null = new NullSessionHandler;
@ -70,7 +72,7 @@ class SessionProvider implements HttpServerInterface {
/**
* {@inheritdoc}
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) {
$sessionName = ini_get('session.name');
$id = array_reduce($request->getHeader('Cookie'), function($accumulator, $cookie) use ($sessionName) {

View File

@ -104,7 +104,7 @@ class WsServer implements HttpServerInterface {
/**
* {@inheritdoc}
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) {
if (null === $request) {
throw new \UnexpectedValueException('$request can not be null');
}