![]() |
VOOZH | about |
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].
Maho's bootstrap process is triggered from various entry points, all converging on the Mage class for initialization.
| Entry Point | File Path | Purpose | Bootstrap Method |
|---|---|---|---|
| Web Application | public/index.php | Handle storefront and admin requests | Mage::run() |
| API Endpoints | public/api.php | SOAP and REST API requests | Mage::init() |
| CLI Commands | bin/maho | Admin and dev CLI tasks | Mage::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
The following diagram illustrates the high-level flow during a standard web bootstrap using Mage::run():
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
The static Mage class (app/Mage.php) is the bootstrap entry hub. Key methods include:
Primary entry point for HTTP web requests as invoked by public/index.php.
setRoot() to determine the absolute application root path app/Mage.php190-208Mage_Core_Model_App via Mage::app() singleton accessor app/Mage.php585-600app()->init() to initialize app environment, resolve current store, and load configuration app/Mage.php647-653Mage::isInstalled() app/Mage.php655maintenance.flag checking and IP bypassing public/index.php51-71Returns the singleton instance of the main application (Mage_Core_Model_App). It performs lazy initialization on first call.
Similar to app(), but allows passing forced store codes or custom options for API or CLI contexts.
Before initialization, Maho determines its root directory via Mage::setRoot():
$_appRoot is already set, it returns early.realpath().Sources: app/Mage.php190-208
Configuration is aggregated in multiple stages by Mage_Core_Model_Config (app/code/core/Mage/Core/Model/Config.php):
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
loadBase())app/etc/*.xml (including local.xml).local.xml object in _refLocalConfigObject for later use app/code/core/Mage/Core/Model/Config.php192CONFIG app/code/core/Mage/Core/Model/Config.php73loadModules())etc/config.xml and merges into the global configuration tree.loadDb())core_config_data table in the database.This staged approach drastically improves performance by using caching and database overrides.
Mage_Core_Model_App)The core application object represents runtime state including current store, website, locale, design, configuration, and front controller.
Environment Setup
_initEnvironment() to configure PHP error handlers, timezone, and memory limits app/code/core/Mage/Core/Model/App.php250mageCoreErrorHandler (defined in app/code/core/Mage/Core/functions.php) for unified error handling app/code/core/Mage/Core/functions.php63-122Configuration Loading
Mage::getConfig().$config->init() to perform all config aggregation phases.Cache Initialization
Store Context Resolution
Area Loading
frontend, adminhtml) such as event observers.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:
Mage_Core_Model_App::run()| Component | Code Entity | Role |
|---|---|---|
| Bootstrap Hub | Mage (app/Mage.php) | Static facade to start bootstrap and store core globals |
| Application Model | Mage_Core_Model_App | Main app runtime state: stores, config, layout, front controller |
| Configuration | Mage_Core_Model_Config | Aggregates XML configuration and DB config with caching |
| Autoloader | vendor/autoload.php | Composer PSR-4 autoloading bootstrap |
| Error Handler | mageCoreErrorHandler() | Central PHP error and exception handling |
| Event Observer Attr | #[Maho\Config\Observer] | Registers event observers using PHP attributes |
| Cron Observer | Mage_Cron_Model_Observer | Example of an observer method using attribute registration |
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:
Refresh this wiki