Nexus API Reference

WsApplication
in package
implements Application

FinalYes
Tags
psalm-api

Decorates any Application (typically HttpApplication) and adds the WebSocket DSL. Compiles to CompiledWsApplication.

Table of Contents

Interfaces

Application

Methods

actor()  : ActorRegistration
channel()  : self
clearRouteCache()  : void
compile()  : CompiledWsApplication
create()  : self
decorate()  : self
delete()  : RouteBuilder
discover()  : self
errorMode()  : self
get()  : RouteBuilder
group()  : RouteGroup
inner()  : Application
middleware()  : self
onException()  : self
paramResolver()  : self
patch()  : RouteBuilder
perRequestActor()  : ActorRegistration
post()  : RouteBuilder
put()  : RouteBuilder
registeredRoutes()  : array<int, RouteSummary>
Snapshot of every route registered so far. Intended for index pages, smoke tests, and admin/debugging tooling.
requiresPoolSingleton()  : bool
withContainer()  : self
withLogger()  : self
withMaxChannels()  : self
Cap the number of simultaneously live channel actors (SEC-002). Once the cap is reached, a new channel connection is refused with a 1013 close instead of spawning an unbounded number of actors/refs/mailboxes from an attacker churning unique channel keys. Dead channels (stopped on last close) free their slot. Default {@see ChannelActorRegistry::DEFAULT_MAX_CHANNELS}.
withMessageSerializer()  : self
withoutDefaultExceptionHandler()  : self
withPoolSingletonSpawner()  : self
withRouteCache()  : self
ws()  : self
wsMiddleware()  : self
Append a PSR-15 middleware applied to EVERY WebSocket upgrade request, before per-route middleware, by the pre-upgrade HandshakeGate. Use this for AuthenticationMiddleware/AuthorizationMiddleware so WebSocket routes share the HTTP auth pipeline and reject unauthorized connections before the 101 switch.

Methods

channel()

public channel(string $path, WebSocketChannelActor> $actorClass, string $key[, callable(): WebSocketChannelActor|null $factory = null ][, array<int, MiddlewareInterface|MiddlewareInterface>$middleware = [] ]) : self
Parameters
$path : string
$actorClass : WebSocketChannelActor>
$key : string
$factory : callable(): WebSocketChannelActor|null = null

Optional constructor. When null the dispatcher zero-arg instantiates the class. Pass a factory when the channel actor needs dependencies (e.g. an EntityRefFactory or a repository) that DI would otherwise supply on an HTTP handler.

$middleware : array<int, MiddlewareInterface|MiddlewareInterface>> = []

Per-route middleware run by the HandshakeGate before the upgrade.

Return values
self

clearRouteCache()

public clearRouteCache() : void
Attributes
#[Override]

delete()

public delete(string $path, string|Closure $handler) : RouteBuilder
Parameters
$path : string
$handler : string|Closure

See self::get() for the closure contract.

Attributes
#[Override]
Return values
RouteBuilder

discover()

public discover(string $directory) : self
Parameters
$directory : string
Attributes
#[Override]
Return values
self

get()

public get(string $path, string|Closure $handler) : RouteBuilder
Parameters
$path : string
$handler : string|Closure

Either a class FQN whose __invoke is resolved by the registry, or a Closure whose params are resolved by registered ParamResolvers (#[FromPrincipal], #[FromBody], ServerRequestInterface, ...) and which returns either a ResponseInterface or a Future<ResponseInterface>.

Attributes
#[Override]
Return values
RouteBuilder

group()

public group(string $prefix, Closure $register) : RouteGroup
Parameters
$prefix : string
$register : Closure
Attributes
#[Override]
Return values
RouteGroup

middleware()

public middleware(string|MiddlewareInterface $middleware) : self
Parameters
$middleware : string|MiddlewareInterface
Attributes
#[Override]
Return values
self

onException()

public onException(TException> $exceptionClass, callable(TException, ServerRequestInterface): ResponseInterface $mapper) : self
Parameters
$exceptionClass : TException>
$mapper : callable(TException, ServerRequestInterface): ResponseInterface
Tags
template
Attributes
#[Override]
Return values
self

paramResolver()

public paramResolver(ParamResolver $resolver[, bool $override = false ]) : self
Parameters
$resolver : ParamResolver
$override : bool = false
Attributes
#[Override]
Return values
self

patch()

public patch(string $path, string|Closure $handler) : RouteBuilder
Parameters
$path : string
$handler : string|Closure

See self::get() for the closure contract.

Attributes
#[Override]
Return values
RouteBuilder

post()

public post(string $path, string|Closure $handler) : RouteBuilder
Parameters
$path : string
$handler : string|Closure

See self::get() for the closure contract.

Attributes
#[Override]
Return values
RouteBuilder

put()

public put(string $path, string|Closure $handler) : RouteBuilder
Parameters
$path : string
$handler : string|Closure

See self::get() for the closure contract.

Attributes
#[Override]
Return values
RouteBuilder

registeredRoutes()

Snapshot of every route registered so far. Intended for index pages, smoke tests, and admin/debugging tooling.

public registeredRoutes() : array<int, RouteSummary>
Attributes
#[Override]
Return values
array<int, RouteSummary>

requiresPoolSingleton()

public requiresPoolSingleton() : bool
Attributes
#[Override]
Return values
bool

withContainer()

public withContainer(ContainerInterface $container) : self
Parameters
$container : ContainerInterface
Return values
self

withLogger()

public withLogger(LoggerInterface $logger) : self
Parameters
$logger : LoggerInterface
Return values
self

withMaxChannels()

Cap the number of simultaneously live channel actors (SEC-002). Once the cap is reached, a new channel connection is refused with a 1013 close instead of spawning an unbounded number of actors/refs/mailboxes from an attacker churning unique channel keys. Dead channels (stopped on last close) free their slot. Default {@see ChannelActorRegistry::DEFAULT_MAX_CHANNELS}.

public withMaxChannels(int $maxChannels) : self
Parameters
$maxChannels : int
Return values
self

withoutDefaultExceptionHandler()

public withoutDefaultExceptionHandler() : self
Attributes
#[Override]
Return values
self

withRouteCache()

public withRouteCache(CacheInterface $cache[, string|null $key = null ]) : self
Parameters
$cache : CacheInterface
$key : string|null = null
Attributes
#[Override]
Return values
self

ws()

public ws(string $path, WebSocketHandler> $handlerClass[, array<int, MiddlewareInterface|MiddlewareInterface>$middleware = [] ]) : self
Parameters
$path : string
$handlerClass : WebSocketHandler>
$middleware : array<int, MiddlewareInterface|MiddlewareInterface>> = []

Per-route middleware run by the HandshakeGate before the upgrade.

Return values
self

wsMiddleware()

Append a PSR-15 middleware applied to EVERY WebSocket upgrade request, before per-route middleware, by the pre-upgrade HandshakeGate. Use this for AuthenticationMiddleware/AuthorizationMiddleware so WebSocket routes share the HTTP auth pipeline and reject unauthorized connections before the 101 switch.

public wsMiddleware(MiddlewareInterface|MiddlewareInterface> $middleware) : self
Parameters
$middleware : MiddlewareInterface|MiddlewareInterface>
Return values
self
On this page

Search results