Skip to content

Application

Antares\Application is the entry point for every Antares app. It exposes a fluent API for wiring up providers, middleware, and the route layer before calling run().

Application::create(string $basePath): self

Creates the application instance. $basePath should be the root of your project (the directory that contains composer.json, .env, and storage/).

->providers(array $providers): static

Registers service providers. These run before route providers and are used for container bindings and singletons.

->routeProviders(array $providers): static

Registers route providers. These are responsible for calling $router->register() with your controller classes.

->middleware(array $middleware): static

Registers global middleware. Middleware runs in order on every request, wrapping the Dispatcher as the innermost layer.

->run(): void

Boots the application, creates a PSR-7 ServerRequest from PHP globals, runs the pipeline, and emits the response.

Application::create(__DIR__ . '/..')
->providers([
AppServiceProvider::class,
DatabaseServiceProvider::class,
])
->routeProviders([
RouteServiceProvider::class,
])
->middleware([
CorsMiddleware::class,
AuthMiddleware::class,
LogMiddleware::class,
])
->run();

Use boot() + handle() to test without emitting output:

$app = Application::create(__DIR__ . '/..')
->providers([AppServiceProvider::class])
->routeProviders([RouteServiceProvider::class]);
$app->boot();
$request = (new Psr17Factory())->createServerRequest('GET', '/users');
$response = $app->handle($request);
assert($response->getStatusCode() === 200);