Understand how Aeros processes HTTP requests from start to finish
Understanding the request lifecycle is essential for building robust applications with Aeros. This guide walks through every step from when a request hits your application to when a response is sent back.
Registers the main AppServiceProvider and sets up core functionality:
public function bootApplication(): ServiceContainer{ if ($this->isAppBooted) { return $this; } (new \App\Providers\AppServiceProvider)->register(); $this->isAppBooted = true; return $this;}
Loads all service providers from configuration and calls their register() methods:
public function registerProviders(): ServiceContainer{ foreach ($this->getProviders() as $providerWithNamespace) { if ($this->isProvider($providerWithNamespace)) { (new $providerWithNamespace)->register(); } } return $this;}
Providers are loaded based on execution mode. Web requests load providers from config('app.providers.web'), while CLI commands load from config('app.providers.cli').
Calls the boot() method on all registered providers:
public function bootProviders(): ServiceContainer{ foreach ($this->getProviders() as $providerWithNamespace) { if ($this->isProvider($providerWithNamespace)) { (new $providerWithNamespace)->boot(); } } return $this;}
The complete bootstrap chain (ServiceContainer.php:95-100):
public function bootstrap(): ServiceContainer{ return $this->bootApplication() ->registerProviders() ->bootProviders();}
The router parses the request URI and matches it against registered routes:
public function dispatch(): mixed{ $route = $this->match($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); if (! $route) { throw new \Exception( sprintf( "ERROR[route] Route '%s:%s' does not match any registered route.", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'] ) ); } // ...}
Before executing the route handler, Aeros runs all registered middleware:
public function dispatch(): mixed{ $route = $this->match($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); // Run middleware for this route self::runMiddlewares($route->getMiddlewares()); $this->currentRoute = $route; return $route->handler()->getContent();}
Middleware are executed sequentially (Router.php:318-334):
public static function runMiddlewares(array $middlewares): void{ foreach ($middlewares as $middleware) { if (! in_array(MiddlewareInterface::class, class_implements($middleware))) { throw new \Exception( sprintf( "ERROR[middleware] Middleware '%s' does not exist or is invalid.", $middleware ) ); } // Pass request and response instances (new $middleware())(app()->request, app()->response); }}
Middleware can modify the request/response or terminate execution early (e.g., for authentication failures).
The handler method determines the type and executes accordingly (Route.php:116-128):
public function handler(): Route{ if (is_callable($this->handler)) { $this->content = ($this->handler)(); } // Controller name if (is_string($this->handler)) { $this->content = $this->callController($this->handler); } return $this;}