ADR - Front Controller¶
Overview¶
The front controller is the entry point of an ADR application. A single call to its run() method boots the container, wires the services, handles the incoming request, emits the response, and returns a process exit code.
Phalcon's front controller follows the front-interop contract, Phalcon\Contracts\Front\FrontController:
The contract is deliberately generic: it describes an entry point into the outermost presentation layer in any context (HTTP, CLI, and so on), so it is not tied to ADR and could be implemented by other stacks as well.
HttpFront¶
Phalcon\ADR\Front\HttpFront is the ready-to-use HTTP front controller, a concrete subclass of Phalcon\ADR\Front\AbstractHttpFront. Its run() performs the whole request lifecycle:
- build the container
- load the environment and register providers
- resolve the request and the application from the container
- handle the request and emit the response
- return
0, or hand anyThrowableto a boot-error handler and return1
Bootstrapping an application is a single line, typically in public/index.php:
Note that run() returns the exit status rather than calling exit() itself, leaving termination to the caller. This is what makes the same front controller usable from a worker loop or a test harness.
Customizing boot¶
AbstractHttpFront exposes template methods you override to shape the boot process. A typical application supplies its own subclass:
<?php
namespace MyApp;
use Phalcon\ADR\Front\AbstractHttpFront;
use Phalcon\Container\Container;
final class AppFront extends AbstractHttpFront
{
protected function loadEnvironment(Container $container): void
{
// load configuration, .env, and so on
}
protected function registerProviders(Container $container): void
{
parent::registerProviders($container); // registers the ADR seams
$container->get('router')
->setBaseNamespace('MyApp\\Action');
}
}
| Method | Purpose |
|---|---|
buildContainer() |
create the DI container (defaults to a new Phalcon\Container\Container) |
loadEnvironment() |
load configuration before services are registered |
registerProviders() |
register services; the default registers the ADR provider |
handleBootError() |
turn a boot-time Throwable into an exit code (defaults to logging and a plain 500) |
handleBootError() covers failures during boot only. Once the application is running, an exception from the pipeline is turned into a response by the error responder, not here.