This commit is contained in:
freek 2018-11-27 21:23:48 +01:00
parent b8de9061fb
commit 9f2221715e
1 changed files with 10 additions and 16 deletions

View File

@ -83,23 +83,17 @@ class Router
protected function getRoute(string $method, string $uri, $action): Route protected function getRoute(string $method, string $uri, $action): Route
{ {
return new Route($uri, ['_controller' => $this->wrapAction($action)], [], [], null, [], [$method]);
}
/** /**
* @param string $action * If the given action is a class that handles WebSockets, then it's not a regular
* controller but a WebSocketHandler that needs to converted to a WsServer.
* *
* @return \Ratchet\WebSocket\WsServer|\Ratchet\Http\HttpServerInterface * If the given action is a regular controller we'll just instanciate it.
*/ */
protected function wrapAction(string $action) $action = is_subclass_of($action, MessageComponentInterface::class)
{ ? $this->createWebSocketsServer($action)
if (is_subclass_of($action, MessageComponentInterface::class)) { : app($action);
return $this->createWebSocketsServer($action);
}
return app($action); return new Route($uri, ['_controller' => $action], [], [], null, [], [$method]);
} }
protected function createWebSocketsServer(MessageComponentInterface $action): WsServer protected function createWebSocketsServer(MessageComponentInterface $action): WsServer