Fix/Feature : Fixing ability to add custom handlers to a route by adding a custom routes method to the router (#150)
Fixing Coding Standards Fixing Coding Standards
This commit is contained in:
parent
5e84ef1ddc
commit
556f4338e8
|
|
@ -44,6 +44,7 @@ class StartWebSocketServer extends Command
|
|||
->configureMessageLogger()
|
||||
->configureConnectionLogger()
|
||||
->registerEchoRoutes()
|
||||
->registerCustomRoutes()
|
||||
->startWebSocketServer();
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +111,13 @@ class StartWebSocketServer extends Command
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function registerCustomRoutes()
|
||||
{
|
||||
WebSocketsRouter::customRoutes();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function startWebSocketServer()
|
||||
{
|
||||
$this->info("Starting the WebSocket server on port {$this->option('port')}...");
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace BeyondCode\LaravelWebSockets\Server;
|
||||
|
||||
use Ratchet\WebSocket\WsServer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Ratchet\WebSocket\MessageComponentInterface;
|
||||
|
|
@ -18,10 +19,12 @@ class Router
|
|||
{
|
||||
/** @var \Symfony\Component\Routing\RouteCollection */
|
||||
protected $routes;
|
||||
protected $customRoutes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->routes = new RouteCollection;
|
||||
$this->customRoutes = new Collection();
|
||||
}
|
||||
|
||||
public function getRoutes(): RouteCollection
|
||||
|
|
@ -39,6 +42,13 @@ class Router
|
|||
$this->get('/apps/{appId}/channels/{channelName}/users', FetchUsersController::class);
|
||||
}
|
||||
|
||||
public function customRoutes()
|
||||
{
|
||||
$this->customRoutes->each(function ($action, $uri) {
|
||||
$this->get($uri, $action);
|
||||
});
|
||||
}
|
||||
|
||||
public function get(string $uri, $action)
|
||||
{
|
||||
$this->addRoute('GET', $uri, $action);
|
||||
|
|
@ -70,7 +80,7 @@ class Router
|
|||
throw InvalidWebSocketController::withController($action);
|
||||
}
|
||||
|
||||
$this->get($uri, $action);
|
||||
$this->customRoutes->put($uri, $action);
|
||||
}
|
||||
|
||||
public function addRoute(string $method, string $uri, $action)
|
||||
|
|
|
|||
Loading…
Reference in New Issue