VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/14.1-mage-static-class

⇱ Mage Static Class | MahoCommerce/maho | DeepWiki


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

Mage Static Class

The Mage class is the central static facade that provides access to all core subsystems in the Maho e-commerce platform. It implements the Service Locator pattern, offering factory methods for object instantiation, configuration access, event dispatching, and application lifecycle management.

Scope: This document covers the Mage class API and its role in the framework. For configuration system details, see Configuration API. For event system usage, see Event System and Observers. For the factory pattern implementation details, see Factory Pattern and Object Instantiation.

Sources: app/Mage.php1-2260


Class Architecture

The Mage class is declared as final and contains only static methods and properties. It serves as the global entry point for the entire application.

Core Class Structure

Title: Mage Static Hub and Internal State


Sources: app/Mage.php18-92


Static Properties

PropertyTypePurpose
$_registryarrayStores shared data accessible via register()/registry()
$_appRootstring|nullApplication root absolute path
$_appMage_Core_Model_App|nullApplication instance singleton
$_configMage_Core_Model_Config|nullConfiguration model singleton
$_events\Maho\Event\Collection|nullEvent collection for observers
$_objects\Maho\DataObject\Cache|nullObject cache instance
$_isDeveloperModeboolDeveloper mode flag
$_isInstalledbool|nullInstallation status cache

Sources: app/Mage.php54-113


Log Level Constants

The class provides constants mapping to Monolog log levels, ensuring modern logging standards while maintaining backward compatibility for legacy code.


Sources: app/Mage.php23-30


Application Bootstrap

Bootstrap Sequence

Title: Application Lifecycle and Initialization


Mage::run()

Primary entry point for web requests. Bootstraps the application and dispatches the request through the front controller.


Parameters:

  • $code - Store/website code to run under (often provided via $_SERVER['MAGE_RUN_CODE'])
  • $type - Scope type: 'store', 'website', 'group'
  • $options - Optional configuration array

Sources: app/Mage.php641-685

Mage::app()

Returns the application singleton, initializing it if necessary. Used throughout the codebase to access application services such as the Request or Response objects.


Sources: app/Mage.php585-600


Factory Methods

The Mage class provides factory methods that delegate to the configuration system for class resolution and instantiation.

Class Resolution Flow

Title: Mapping Factory Aliases to PHP Entities


Model Factory Methods

Mage::getModel()

Creates a new instance of a model class based on a grouped class name.


Class alias format: module/model_path (e.g., 'catalog/product', 'core/store')

Sources: app/Mage.php411-414 app/code/core/Mage/CatalogInventory/Model/Observer.php51 app/code/core/Mage/CatalogInventory/Model/Observer.php137 app/code/core/Mage/GiftMessage/Model/Observer.php83 app/code/core/Mage/GiftMessage/Model/Observer.php152 app/code/core/Mage/GiftMessage/Model/Observer.php190 app/code/core/Mage/Review/Model/Observer.php60 app/code/core/Maho/AdminActivityLog/Model/Observer.php58 app/code/core/Maho/AdminActivityLog/Model/Observer.php75 app/code/core/Maho/AdminActivityLog/Model/Observer.php95

Mage::getSingleton()

Returns a singleton instance of a model, creating it on first access and caching it in the registry.


Registry key format: _singleton/{modelAlias}

Sources: app/Mage.php426-433 app/code/core/Mage/CatalogInventory/Model/Observer.php129 app/code/core/Mage/Weee/Model/Observer.php27 app/code/core/Mage/Weee/Model/Observer.php54 app/code/core/Mage/Weee/Model/Observer.php86 app/code/core/Mage/Weee/Model/Observer.php125 app/code/core/Mage/Weee/Model/Observer.php128 app/code/core/Mage/Weee/Model/Observer.php163 app/code/core/Mage/Catalog/Model/Product/Compare/Item.php206 app/code/core/Mage/Catalog/Model/Product/Compare/Item.php220 app/code/core/Mage/Review/Model/Observer.php25 app/code/core/Maho/AdminActivityLog/Model/Observer.php34 app/code/core/Maho/AdminActivityLog/Model/Observer.php73

Mage::getResourceModel()

Creates a resource model instance. This method is heavily used for database interaction, such as retrieving the resource for configuration or product persistence.


Sources: app/Mage.php446-449 app/code/core/Mage/Core/Model/Config.php239-241 app/code/core/Mage/Tag/Model/Tag.php244 app/code/core/Mage/Tag/Model/Tag.php251


Configuration Access

Mage::getStoreConfig()

Retrieves configuration value for a specific store scope. This is the primary way to access settings defined in config.xml or the core_config_data table.


Sources: app/Mage.php277-280

Mage::getStoreConfigFlag()

Returns boolean interpretation of configuration value. Useful for checking feature toggles.


Sources: app/Mage.php305-313

Mage::getConfig()

Returns the configuration singleton Mage_Core_Model_Config.


Sources: app/Mage.php354-357 app/code/core/Mage/Core/Model/Config.php13-73


Event System

Mage::dispatchEvent()

Dispatches an event to all registered observers. This is the core extensibility mechanism in Maho. Maho also supports the #[Maho\Config\Observer] attribute for registering observers directly on methods.


Sources: app/Mage.php392-398 app/code/core/Mage/CatalogInventory/Model/Observer.php44-45 app/code/core/Maho/AdminActivityLog/Model/Observer.php48


Registry System

Registry Data Flow

Title: Shared Application State in Registry


Mage::register()

Stores a value in the global registry. If the key already exists and $graceful is false, it throws a Mage_Core_Exception.


Sources: app/Mage.php147-156

Mage::registry()

Retrieves a value from the registry.


Sources: app/Mage.php179-182


Logging and Exceptions

Mage::log()

Logs a message using the Monolog integration. If no file is specified, it defaults to the configuration setting.


Sources: app/Mage.php772-786

Mage::logException()

Logs an exception object to the exception log file.


Sources: app/Mage.php796-814 app/code/core/Maho/AdminActivityLog/Model/Observer.php61 app/code/core/Maho/AdminActivityLog/Model/Observer.php78 app/code/core/Maho/AdminActivityLog/Model/Observer.php98 app/code/core/Maho/AdminActivityLog/Model/Observer.php130

Mage::printException()

Displays exception details (in developer mode) or triggers an error report page.


Sources: app/Mage.php824-854


State Management

Mage::reset()

Resets all static properties to their defaults. This is critical for isolation in unit and integration tests.


Resets:

  • $_registry
  • $_appRoot
  • $_app
  • $_config
  • $_events
  • $_objects
  • $_isDeveloperMode
  • $_isInstalled

Sources: app/Mage.php126-137

Mage::getVersion()

Returns the current Maho version string.


Sources: app/Mage.php118-121