Application
Solo\Application\Application bootstraps the application in its constructor and handles requests as a PSR-15 request handler. See Lifecycle for the full sequence.
final readonly class Application implements Psr\Http\Server\RequestHandlerInterfaceProperties
| Property | Type | Description |
|---|---|---|
$config | Config | The configuration passed to the constructor |
$container | Solo\Contracts\Container\WritableContainerInterface | The container passed to the constructor, or the one it created |
$router | Solo\Router\Router | The built router, also registered in the container as Solo\Router\Router |
All three are public and readonly.
__construct()
public function __construct(
Config $config,
?WritableContainerInterface $container = null
)- Uses
$container, or creates aSolo\Container\Container. - Registers
Config,ContainerInterface,WritableContainerInterface,RouteDispatcher,RoutingMiddlewareandRoutingErrorMiddlewarein the container. - Instantiates each class in
$config->providerswithout arguments and calls itsregister()with the container. - Builds the router: calls the callable returned by
$config->routesPathwith a newSolo\Router\RouteCollectorand the container, then builds the collector. With$config->routesCachePathset, loads the router from that file instead, and builds and writes it only when the file is missing or was written by an incompatible version of Solo Router. - Registers the router as
Solo\Router\Router.
Throws:
RuntimeExceptionif no container is passed andsolophp/containeris not installed;InvalidArgumentExceptionif a provider has no publicregister()method;RuntimeExceptionif the routes file is not found, or the route cache file cannot be written;UnexpectedValueExceptionif the routes file does not return a callable;InvalidArgumentExceptionfrom Solo Router for invalid routes, such as a duplicate name or path;LogicExceptionif the route cache is written and a route holds a closure or another object.
handle()
public function handle(ServerRequestInterface $request): ResponseInterfaceRuns the request through $config->middleware to the RouteDispatcher and returns the response. It does not use the emitter.
A MiddlewarePipeline is created for every call. The RoutingErrorMiddleware from the container wraps it, so a RoutingException that no middleware caught becomes a response of its status and headers; see the fallback. Every other exception from a middleware or a handler propagates.
Requires Psr\Http\Message\ResponseFactoryInterface in the container.
$response = $app->handle($request);run()
public function run(?ServerRequestInterface $request = null): voidHandles the request and emits the response:
- Without
$request, resolvesPsr\Http\Message\ServerRequestInterfacefrom the container. - Calls
handle(). - Resolves
Solo\Contracts\Http\EmitterInterfacefrom the container and callsemit()with the response.
The emitter is resolved after handling, so the request can still replace it. In a long-running process, pass every request explicitly: see Workers and Emitting.
$app->run();