⌘K
Docs / Bootstrap / Request Lifecycle / Bootstrap & Request Lifecycle

Bootstrap & Request Lifecycle

The Laika framework utilizes a centralized bootstrap process to ensure a consistent environment for both web and CLI requests. Every execution begins at an entrypoint, defines the application root, and invokes the core boot layer before proceeding to specific logic (routing or command execution).


Lifecycle Overview

The lifecycle follows a linear path from the entrypoint to the final output. The framework distinguishes between two primary SAPIs (Server APIs): fpm-fcgi/apache2handler (Web) and cli (Terminal).


Web Entrypoint

The web lifecycle is managed by index.php, acting as a front-controller. All incoming HTTP requests are funneled through this file via server rewrite rules, such as those defined in nginx.conf which use try_files to redirect to index.php nginx.conf.

  1. Initialization: Loads the bootstrapper via lf-boot/app.php index.php
  2. Routing: Invokes the static dispatch() method on the Laika\Core\App\Router class. This analyzes the request URI and matches it against definitions in the route files.


Server Configuration & Rewrites

To enable the Front-Controller pattern, the web server must be configured to redirect all requests that do not match a physical file to index.php.


Apache Configuration (.htaccess)

The .htaccess file uses mod_rewrite to manage traffic. It includes a specific rule to preserve the Authorization header, which is often stripped by Apache in CGI mode, ensuring API authentication works correctly.

<IfModule mod_rewrite.c>
  RewriteEngine On
  
  # Handle Authorization Header
  RewriteCond %{HTTP:Authorization} .
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>


Nginx Configuration (nginx.conf)

The Nginx configuration achieves the same result using the location block and try_files directive.

location / {
  # Handle Authorization Header
  if ($http_authorization != "") {
    set $auth_header $http_authorization;
  }

  try_files $uri /index.php$is_args$args;
}