diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index d3de200..e7e023c 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -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); } diff --git a/src/Ratchet/Http/HttpServerInterface.php b/src/Ratchet/Http/HttpServerInterface.php index 2c37c49..5990d03 100644 --- a/src/Ratchet/Http/HttpServerInterface.php +++ b/src/Ratchet/Http/HttpServerInterface.php @@ -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); } diff --git a/src/Ratchet/Http/NoOpHttpServerController.php b/src/Ratchet/Http/NoOpHttpServerController.php index 4f72e66..fcaca02 100644 --- a/src/Ratchet/Http/NoOpHttpServerController.php +++ b/src/Ratchet/Http/NoOpHttpServerController.php @@ -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) { diff --git a/src/Ratchet/Http/OriginCheck.php b/src/Ratchet/Http/OriginCheck.php index 2bdc0f7..29b2dad 100644 --- a/src/Ratchet/Http/OriginCheck.php +++ b/src/Ratchet/Http/OriginCheck.php @@ -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; diff --git a/src/Ratchet/Http/Router.php b/src/Ratchet/Http/Router.php index 2bd5942..04ea395 100644 --- a/src/Ratchet/Http/Router.php +++ b/src/Ratchet/Http/Router.php @@ -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'); } diff --git a/src/Ratchet/Session/SessionProvider.php b/src/Ratchet/Session/SessionProvider.php index 44276c5..2f42a17 100644 --- a/src/Ratchet/Session/SessionProvider.php +++ b/src/Ratchet/Session/SessionProvider.php @@ -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) { diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 27795ca..2b1767c 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -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'); }