Skip to content

Commit

Permalink
Support configuring the error URI resolver through the application class
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Dec 13, 2023
1 parent cdf99c5 commit f05d1c9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use BabDev\WebSocket\Server\Http\Middleware\RestrictToAllowedOrigins;
use BabDev\WebSocket\Server\Session\Middleware\InitializeSession;
use BabDev\WebSocket\Server\WAMP\ArrayTopicRegistry;
use BabDev\WebSocket\Server\WAMP\DefaultErrorUriResolver;
use BabDev\WebSocket\Server\WAMP\ErrorUriResolver;
use BabDev\WebSocket\Server\WAMP\MessageHandler\DefaultMessageHandlerResolver;
use BabDev\WebSocket\Server\WAMP\MessageHandler\MessageHandlerResolver;
use BabDev\WebSocket\Server\WAMP\Middleware\DispatchMessageToHandler;
Expand Down Expand Up @@ -41,6 +43,8 @@ final class Application

private MessageHandlerResolver $messageHandlerResolver;

private ErrorUriResolver $errorUriResolver;

private ?EventDispatcherInterface $dispatcher = null;

private ?SessionFactoryInterface $sessionFactory = null;
Expand Down Expand Up @@ -73,14 +77,15 @@ public function __construct(
$this->routeCollection = new RouteCollection(),
new RequestContext(),
);
$this->errorUriResolver = new DefaultErrorUriResolver();
$this->messageHandlerResolver = new DefaultMessageHandlerResolver();
}

public function run(): void
{
$topicRegistry = new ArrayTopicRegistry();

$middleware = new DispatchMessageToHandler($this->matcher, $this->messageHandlerResolver, $this->dispatcher);
$middleware = new DispatchMessageToHandler($this->matcher, $this->messageHandlerResolver, $this->dispatcher, $this->errorUriResolver);
$middleware = new UpdateTopicSubscriptions($middleware, $topicRegistry);
$middleware = new ParseWAMPMessage($middleware, $topicRegistry);

Expand Down Expand Up @@ -116,6 +121,16 @@ public function route(string $path, MessageHandler|MessageMiddleware|string $han
return $this;
}

/**
* Replaces the {@see ErrorUriResolver} implementation to be used by the application.
*/
public function withErrorUriResolver(ErrorUriResolver $errorUriResolver): self
{
$this->errorUriResolver = $errorUriResolver;

return $this;
}

/**
* Registers an event dispatcher for use with middleware that emit events.
*/
Expand Down

0 comments on commit f05d1c9

Please sign in to comment.