AmphpServer
in package
Stand-alone amphp/http-server v3 boot helper.
Port of the setup_application + ip_filter_middleware pair from
aiogram/webhook/aiohttp_server.py:22-78.
Router deviation
amphp/http-server-router is not installed as a project dependency.
AmphpServer::run() therefore builds a PathRouter — a minimal
in-house RequestHandler that:
- Matches an exact path (
'/webhook') or a single-segment parameterised path ('/webhook/{bot_token}'). - Rejects any request whose path does not match with
404 Not Found. - Rejects non-POST methods with
405 Method Not Allowed. - Delegates matching requests to the supplied
BaseRequestHandler.
PathRouter is intentionally package-private. Callers that need
full routing flexibility should compose their own SocketHttpServer and
call Setup::register() instead.
Dispatcher lifecycle wiring
run() wires Dispatcher::emitStartup and Dispatcher::emitShutdown
to the server's onStart / onStop callbacks, mirroring upstream's
setup_application at aiohttp_server.py:22-40:
app.on_startup.append(on_startup)
app.on_shutdown.append(on_shutdown)
Table of Contents
Methods
- run() : SocketHttpServer
- Boot an `amphp/http-server` v3 instance with the supplied handler.
Methods
run()
Boot an `amphp/http-server` v3 instance with the supplied handler.
public
static run(BaseRequestHandler $handler, Dispatcher $dispatcher[, string $host = '0.0.0.0' ][, int $port = 8443 ][, string $path = '/webhook' ][, null|IpFilter $ipFilter = null ][, null|LoggerInterface $logger = null ][, array<string, mixed> $workflowData = [] ]) : SocketHttpServer
Steps performed:
- Build a PathRouter mapping POST
$path→$handler. - Optionally wrap it with IpFilterMiddleware when
$ipFilteris provided (mirrors upstreamip_filter_middleware). - Create a
SocketHttpServerviacreateForDirectAccess. - Wire
$dispatcher->emitStartup/emitShutdownonto the server'sonStart/onStophooks. - Call
expose($host:$port)+start(handler, errorHandler)to bind the listening socket and launch the accept loop. - Return the running
SocketHttpServerso the caller can stop it and/or await its lifecycle.
Parameters
- $handler : BaseRequestHandler
-
Webhook handler (Tasks 6.2–6.4).
- $dispatcher : Dispatcher
-
Dispatcher whose startup/shutdown observers are wired to server events.
- $host : string = '0.0.0.0'
-
Bind host (default
'0.0.0.0'). - $port : int = 8443
-
Listen port (default
8443). - $path : string = '/webhook'
-
URL path, e.g.
'/webhook'or'/webhook/{bot_token}'. - $ipFilter : null|IpFilter = null
-
Optional CIDR allowlist;
nulldisables IP gating. - $logger : null|LoggerInterface = null
-
PSR-3 logger for the server. Defaults to a no-op
NullLogger. - $workflowData : array<string, mixed> = []
-
Extra kwargs forwarded to the dispatcher startup/shutdown emitters.
Return values
SocketHttpServer —The running server instance.