VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/3.1-application-bootstrap

⇱ Application Bootstrap | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Application Bootstrap

Purpose and Scope

This document explains the bootstrap process of the Maho e-commerce platform — a modernized Magento fork. It details how the application initializes itself from the first entry point (like a web request) through configuration loading, environment setup, module initialization, and preparing the application context until it is ready for request processing or other runtime operations.

The page focuses on the static Mage::run() method, which drives the bootstrap lifecycle for web applications, the initialization of the core application model Mage_Core_Model_App, and the configuration aggregation managed by Mage_Core_Model_Config. It also explains auxiliary bootstrap mechanisms such as application root detection, error handling, and event observer registration using the new PHP attribute system.

For related details on request handling after bootstrap, see [3.2 Request Flow and Front Controller]. For full configuration system details, see [3.3 Configuration System].


Entry Points

Maho's bootstrap process is triggered from various entry points, all converging on the Mage class for initialization.

Entry PointFile PathPurposeBootstrap Method
Web Applicationpublic/index.phpHandle storefront and admin requestsMage::run()
API Endpointspublic/api.phpSOAP and REST API requestsMage::init()
CLI Commandsbin/mahoAdmin and dev CLI tasksMage::init() or Mage::app()

A key modernization is present in public/index.php that quickly exits early on requests for static assets (like images, CSS, JS) to avoid full application bootstrap for 404 responses public/index.php16-37 All entry points include or require Composer's autoloader for class loading public/index.php39

The bootstrap starts with setting the application root path and then initializing the application via calls such as Mage::run() or Mage::init(). The static Mage class serves as the central hub managing these bootstrap sequences app/Mage.php18-19

Sources: public/index.php16-73 app/Mage.php18-19 public/api.php13-24


Bootstrap Sequence Overview

The following diagram illustrates the high-level flow during a standard web bootstrap using Mage::run():

Bootstrap Call Flow


This process completes when the front controller is ready to route the request.

Sources: app/Mage.php639-681 app/code/core/Mage/Core/Model/App.php248-272 app/code/core/Mage/Core/Model/Config.php275-279 public/index.php73


Static Mage Class Initialization

The static Mage class (app/Mage.php) is the bootstrap entry hub. Key methods include:

Mage::run()

Primary entry point for HTTP web requests as invoked by public/index.php.

  • Calls setRoot() to determine the absolute application root path app/Mage.php190-208
  • Instantiates the Mage_Core_Model_App via Mage::app() singleton accessor app/Mage.php585-600
  • Invokes app()->init() to initialize app environment, resolve current store, and load configuration app/Mage.php647-653
  • Checks if the system is installed with Mage::isInstalled() app/Mage.php655
  • Handles maintenance mode via maintenance.flag checking and IP bypassing public/index.php51-71
  • Wraps execution in exception handlers that invoke error pages or log messaging app/Mage.php659-680

Mage::app()

Returns the singleton instance of the main application (Mage_Core_Model_App). It performs lazy initialization on first call.

Mage::init()

Similar to app(), but allows passing forced store codes or custom options for API or CLI contexts.


Application Root Detection

Before initialization, Maho determines its root directory via Mage::setRoot():

  • If $_appRoot is already set, it returns early.
  • If no argument supplied, it tries to infer root using the current working directory's parent (app/Mage.php196-198).
  • Resolves the path with realpath().
  • Validates directory existence and readability.
  • Throws exception if path invalid.

Root Path Logic Diagram


Sources: app/Mage.php190-208


Configuration Initialization Stages

Configuration is aggregated in multiple stages by Mage_Core_Model_Config (app/code/core/Mage/Core/Model/Config.php):

Hardcoded Core Modules Order

The class maintains a fixed order of core modules to ensure consistent loading order and dependencies app/code/core/Mage/Core/Model/Config.php15-73

1. Base Configuration (loadBase())

2. Configuration Cache Loading

3. Module Configuration Loading (loadModules())

  • Loads each module's etc/config.xml and merges into the global configuration tree.
  • Respects module activation and dependencies.

4. Database Configuration Loading (loadDb())

  • Loads dynamic configuration values from the core_config_data table in the database.
  • Overrides static XML configuration with database values.

This staged approach drastically improves performance by using caching and database overrides.


Application Model (Mage_Core_Model_App)

The core application object represents runtime state including current store, website, locale, design, configuration, and front controller.

Initialization Responsibilities

  1. Environment Setup

  2. Configuration Loading

    • Retrieves the global config singleton via Mage::getConfig().
    • Calls $config->init() to perform all config aggregation phases.
  3. Cache Initialization

  4. Store Context Resolution

  5. Area Loading

    • Loads configuration sections specific to areas (like frontend, adminhtml) such as event observers.
  6. Event System

    • Sets observers using the modern PHP attribute system #[Maho\Config\Observer] lib/Maho/Config/Observer.php27

    • For example, Mage_Cron_Model_Observer registers cron status check with:

      
      

Lifecycle Control via Mage_Core_Model_App::run()

  • After initialization, the app runs the front controller to process the HTTP request.
  • Dispatches pre-dispatch, controller action, and post-dispatch events.

Summary Table: Key Bootstrap Components

ComponentCode EntityRole
Bootstrap HubMage (app/Mage.php)Static facade to start bootstrap and store core globals
Application ModelMage_Core_Model_AppMain app runtime state: stores, config, layout, front controller
ConfigurationMage_Core_Model_ConfigAggregates XML configuration and DB config with caching
Autoloadervendor/autoload.phpComposer PSR-4 autoloading bootstrap
Error HandlermageCoreErrorHandler()Central PHP error and exception handling
Event Observer Attr#[Maho\Config\Observer]Registers event observers using PHP attributes
Cron ObserverMage_Cron_Model_ObserverExample of an observer method using attribute registration

Cross-References: Code Entities to Bootstrap Concepts

Natural Language to Code Entity Space: Bootstrap Overview


Observers and Attribute Registration



Summary

The Maho Application Bootstrap relies on a robust static facade (Mage), comprehensive configuration management (Mage_Core_Model_Config), and a central application model (Mage_Core_Model_App) to prepare the environment for HTTP requests, API calls, or CLI usage. Boosted by PHP 8 attributes for dynamic event observer registration and multi-stage config loading with caching, the bootstrap process balances flexibility, performance, and extensibility in a Magento-modernized architecture.


Sources: